We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3412c01 commit 820fd00Copy full SHA for 820fd00
2692-take-gifts-from-the-richest-pile/solution.py
@@ -0,0 +1,17 @@
1
+class Solution:
2
+ def pickGifts(self, gifts: List[int], k: int) -> int:
3
+ # py has min heap so use - minus sign to simulate max heap
4
+ h = [-g for g in gifts]
5
+ heapq.heapify(h)
6
+
7
+ for _ in range(k):
8
+ maxElement = -heapq.heappop(h)
9
10
+ heapq.heappush(h, -math.floor(math.sqrt(maxElement)))
11
12
+ res = 0
13
+ while h:
14
+ # now use - to make it back positive
15
+ res -= heapq.heappop(h)
16
17
+ return res
0 commit comments