Pregunta de entrevista de Yelp

It is just an algorithm question.