Question d’entretien chez Google

Solve this leet code under 30min