Hindi Explanation here: kzbin.info/www/bejne/g6uwhJl6a9ubirc
@darshankumar554610 күн бұрын
import heapq class Solution: def minimizedMaximum(self, n: int, quantities: List[int]) -> int: m=len(quantities) minHeap=[] for i in quantities: # O(m) minHeap.append((-i,i,1)) # avg quantity per store , total quantity,#no of stores heapq.heapify(minHeap) # O(m) print(minHeap) print('n-m =',n-m) #O((n-m)logm) for i in range(n-m): #O(n-m) _,totalQuantity,totalStores=heapq.heappop(minHeap) #O(logm) totalStores+=1 avg=(totalQuantity/totalStores) heapq.heappush(minHeap,(-avg,totalQuantity,totalStores)) #O(logm) print(minHeap) avg,_,_=heapq.heappop(minHeap) avg=avg*(-1) return ceil(avg)