Pregunta de entrevista de Bloomberg

It was an easy level leetcode question.