MathWorks Interview Question

Pretty simple algorithm based question