Bloomberg interview question

leetcode easy and medium problem