Skip to content

Commit 94f1526

Browse files
committed
Dec 12
1 parent 496f447 commit 94f1526

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

2024-12-December-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
| December 9 | [3152. Special Array II](https://leetcode.com/problems/special-array-ii/) | Medium | Solved |
1515
| December 10 | [2981. Find Longest Special Substring That Occurs Thrice I](https://leetcode.com/problems/find-longest-special-substring-that-occurs-thrice-i/) | Medium | Unsolved |
1616
| December 11 | [2779. Maximum Beauty of an Array After Applying Operation](https://leetcode.com/problems/maximum-beauty-of-an-array-after-applying-operation/) | Medium | Unsolved |
17-
| December 12 | []() | | |
17+
| December 12 | [2558. Take Gifts From the Richest Pile](https://leetcode.com/problems/take-gifts-from-the-richest-pile/) | Easy | Solved |
1818
| December 13 | []() | | |
1919
| December 14 | []() | | |
2020
| December 15 | []() | | |
@@ -38,6 +38,6 @@
3838
## Summary
3939
| Level | Problems | Solved | Unsolved |
4040
| --- | --- | --- | --- |
41-
| Easy | 2 | 2 | 0 |
41+
| Easy | 3 | 3 | 0 |
4242
| Medium | 9 | 6 | 3 |
4343
| Hard | 0 | 0 | 0 |
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from heapq import heapify, heappop, heappush
2+
from math import isqrt
3+
from typing import List
4+
5+
6+
class Solution:
7+
def pickGifts(self, gifts: List[int], k: int) -> int:
8+
heap = [-gift for gift in gifts]
9+
heapify(heap)
10+
for _ in range(k):
11+
max_pile = -heappop(heap)
12+
heappush(heap, -isqrt(max_pile))
13+
return -sum(heap)
14+
15+
16+
def main():
17+
gifts = [25, 64, 9, 4, 100]
18+
k = 4
19+
assert Solution().pickGifts(gifts, k) == 29
20+
21+
gifts = [1, 1, 1, 1]
22+
k = 4
23+
assert Solution().pickGifts(gifts, k) == 4
24+
25+
26+
if __name__ == '__main__':
27+
main()

0 commit comments

Comments
 (0)