Databricks interview question

One of leetcode hard difficulty questions