Bloomberg Interview Question

I was a question from leetcode.