Bloomberg interview question

leetcode style medium hard question