Amazon Interview Question

Leetcode medium problem on heap