Oracle interview question

a leetcode medium problem using heap