MathWorks interview question

coding like leetcode. c++ knowledge