Bloomberg Interview Question

leetcode question from their tagged - medium