Pregunta de entrevista de Block

Regular CS and algorithm question. Nothing tricky.