MathWorks interview question

LeetCode type question for Algorithm and data structure