Bloomberg interview question

I got a leetcode easy/medium type problem-solving.