UBS interview question

leetcode easy medium question that wa bit difficult