Pregunta de entrevista de Uber

The difficulty is around leetcode medium plus.