Bloomberg interview question

I was a question from leetcode.