Pregunta de entrevista de Google

Leetcode Medium - Hard question with multiple followups