Bloomberg interview question

2 Leetcode medium difficulty within 1 hour