Databricks Interview Question

One of leetcode hard difficulty questions