Grokking the Coding Interview: Patterns for Coding Questions
Vote

0% completed

​

Problem Challenge 2: Scheduling Tasks (hard)

.....

.....

.....

Like the course? Get enrolled and start learning!
A

Anonymous

· 2 years ago

from heapq import * from collections import deque, Counter class Solution:   def reorganizeString(self, str, k):     counts = Counter(str)     heap = [       (-value, char) for char, value in counts.items()     ]     heapify(heap)     if -heap[0][0] > (len(str) + k - 1)//k:       return ''         res = list('_' * len(str))     i = 0     offset = 0     while heap:       count, char = heappop(heap)       while count < 0:         res[i] = char         i += k         if i >= len(res):           offset += 1           i = offset         count += 1     return ''.join(res)
A

Anonymous

· 2 years ago

  • str consists of only lowercase English letters. - This is not correct as there are uppercase letters also.

Reading Progress

0%


Vote for new content