Bloomberg interview question

It was a medium-difficulty leetcode question.