Today, we challenge you to create a function that uses a stack to determine if a given string of parentheses is balanced. A string is considered balanced if every opening parenthesis (i.e., (
, {
, [
) has a corresponding closing parenthesis (i.e., )
, }
, ]
) in the correct order.
Implement a function isBalanced
(or similarly named) that takes a string as input and returns a boolean indicating whether the string is balanced.
Example:
Input: "{[()()]}"
Output: true
Input: "{[(])}"
Output: false
Stacks are fundamental data structures widely used in programming for tasks such as syntax parsing, which is useful in many applications. In celebration of this skill, consider how stacks can help keep order in even the busiest times of the year, such as the holidays!
Your solution should include a function with the following signature, and you may add helper functions if needed.