Implement a function that checks whether a given string containing various types of brackets (()
, {}
, and []
) is balanced. A string is considered balanced if every opening bracket has a corresponding closing bracket in the correct order. Use a stack to solve this problem.
true
if the input string is balanced, and false
otherwise.For example:
Input: "[(){()}]"
Output: true
Input: "[(])"
Output: false
As today, April 18, is a day with fascinating historical events, think of this challenge as a way to honor the timeless nature of algorithms that endure through centuries. Write clean and efficient code that could stand the test of time!
The function/method should take a single string parameter and return a boolean indicating whether the string is balanced.