Bloomberg interview question

Solve a coding question leetcode medium