Databricks Interview Question

Leetcode style question, using heap