Pregunta de entrevista de Bloomberg

I got a leetcode easy/medium type problem-solving.