Pregunta de entrevista de Uber

Coding question - average difficulty