Citadel Interview Question

Heap based question for techincal problem