MathWorks interview question

Stack based interview question - from leetcode