Pregunta de entrevista de Rocksbox

Very reasonable and practical coding problem.