MathWorks Interview Question

Stack based interview question - from leetcode