Pregunta de entrevista de Glassdoor

Leet code medium but more time consuming.