Pergunta de entrevista da empresa Bloomberg

Leetcode question and about medium difficulty.