Pregunta de entrevista de Bloomberg

Leetcode question and about medium difficulty.