Bloomberg Interview Question

One leetcode problem, and optimized solution of the problem.