Answer: ZETWERK Hiring Challenge | Interview Question | Off-Campus OA (2024)

Answer · Posted Jun 2026

Approach Since we repeatedly need the largest pile: Store all piles in a Max Heap (Priority Queue). Extract the largest pile. Replace it with its floor square root. Repeat k times. Sum all remaining values. Strategy Use a Max Heap to efficiently access the largest pile. Each extraction and insertion takes O(log n). Perform exactly k operations. Java Code import java.util.*; class Solution { public long pickGifts(int[] gifts, int k) { PriorityQueue<Integer> maxHeap = new PriorityQueue<>(Collections.reverseOrder()); for (int gift : ...

The full answer & interview discussion are available to premium members.

Log in Create a free account