Take Gifts From the Richest Pile
LeetCode 2558 • Easy • Heaps
gifts = [25,64,9,4,100], k = 4 → 29. Each second: take richest pile, leave ⌊√x⌋.
TimeO(n + k log n)
SpaceO(n)
sec: 0/4popped: —push √: —sum: —
Max (pop)
Push ⌊√x⌋
Heap pile
heap[ ]
k left4
Ready
Press Play or Step to walk the algorithm.