Pregunta de entrevista de MathWorks

Pretty simple algorithm based question