Databricks interview question

Leetcode style question, using heap