Mark As Completed Discussion

Stack Exercises

To reinforce your understanding of stacks, let's practice some stack-related problems. These exercises will help you solidify your knowledge of stack operations and their applications. Solve each problem and compare your solution with the provided solution code.

  1. Valid Parentheses: Write a function isValid that takes a string as input and determines if the string's parentheses are properly balanced.

  2. Next Greater Element: Given an array of integers, find the next greater element for each element in the array. The next greater element is the first element to the right that is greater than the current element. If there is no such element, the output should be -1.

  3. Evaluate Reverse Polish Notation: Write a function evalRPN that evaluates a given arithmetic expression in Reverse Polish Notation (RPN).

Remember to review the concepts covered in the previous screens and apply them to these exercises. Good luck!