2692. Take Gifts From the Richest Pile
My accepted Python solution to LeetCode problem 2692, Take Gifts From the Richest Pile, running in 0ms.
- Difficulty: Easy
- Python
- Runtime 0ms
- Memory 17.4MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 0ms, memory 17.4MB, accepted 2026-01-01.
class Solution:
def pickGifts(self, gifts: List[int], k: int) -> int:
import heapq
# Use negative values for max heap
heap = [-g for g in gifts]
heapq.heapify(heap)
for _ in range(k):
max_gifts = -heapq.heappop(heap)
new_gifts = int(max_gifts ** 0.5)
heapq.heappush(heap, -new_gifts)
return -sum(heap)