Pergunta de entrevista da empresa MathWorks

Pretty simple algorithm based question