Pergunta de entrevista da empresa Bloomberg

one from the leetcode question