Databricks interview question

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