Pregunta de entrevista de Bloomberg

I was a question from leetcode.