MathWorks interview question

Solve the coding questions in any language