Pregunta de entrevista de Google

Difficult data structure and algorithms question