Databricks Interview Question

Standard algorithm question.