Pregunta de entrevista de Clover

General algorithm question with efficiency accounted for