MathWorks interview question

Pretty simple algorithm based question