Pregunta de entrevista de Google

Algorithm questions, nothing extremely difficult.