Pergunta de entrevista da empresa Bloomberg

It was a medium-difficulty leetcode question.