Bloomberg Interview Question

one from the leetcode question