import heapq class Solution: def getFinalState(self, nums: List[int], k: int, multiplier: int) -> List[int]: minheap=[] n=len(nums) for i in range(n): heapq.heappush(minheap,(nums[i],i)) #print(minheap) for i in range(k): #print('k=',k) value,indexx=minheap[0] value*=multiplier nums[indexx]=value heapq.heapreplace(minheap,(value,indexx)) #print(minheap) return nums
@darshankumar554626 күн бұрын
English Explanation: kzbin.info/www/bejne/lZu9mZqnZadobdE
@darshankumar554626 күн бұрын
#tc=O(n+klogn) #sc=O(n) import heapq class Solution: def getFinalState(self, nums: List[int], k: int, multiplier: int) -> List[int]: minheap=[] n=len(nums) for i in range(n): #O(n) minheap.append((nums[i],i)) heapq.heapify(minheap) #O(n) print(minheap) for i in range(k): print('k=',k) value,indexx=heapq.heappop(minheap) value*=multiplier nums[indexx]=value heapq.heappush(minheap,(value,indexx)) print(minheap) return nums