Bloomberg Interview Question

It was a medium-difficulty leetcode question.