Databricks interview question

Question was a standard leetcode medium/hard