Amazon interview question

Leetcode medium problem on heap