Bloomberg interview question

One leetcode problem, and optimized solution of the problem.