Databricks Interview Question

Q: Codility-like questions, it's around the medium diffiulty