Pregunta de entrevista de Bloomberg

It was a medium-difficulty leetcode question.