UBS interview question

LeetCode - medium question to answer