Pregunta de entrevista de Exodus

How I would solve a specific algorithm