shlogg · Early preview
Md Ariful Haque @mah-shamim

Efficient Gift Distribution Using Max-Heap Data Structure

Use max-heap (priority queue) to efficiently pick & leave gifts, then sum remaining gifts after k seconds.

2558. Take Gifts From the Richest Pile
Difficulty: Easy
Topics: Array, Heap (Priority Queue), Simulation
You are given an integer array gifts denoting the number of gifts in various piles. Every second, you do the following:

Choose the pile with the maximum number of gifts.
If there is more than one pile with the maximum number of gifts, choose any.
Leave behind the floor of the square root of the number of gifts in the pile. Take the rest of the gifts.

Return the number of gifts remaining after k seconds.
Example 1:

Input: gifts = [25,64,9,4,100], k = 4
Output: 29
Explanation: The gifts ar...