Bracket Balance Checker

Stack Data Structures Brackets Algorithm

Bracket Balance Checker

In this problem, your task is to determine whether a given string containing various types of brackets is valid. A string is considered valid if:

  • Every opening bracket has a corresponding closing bracket of the same type.
  • The brackets close in the correct order.

Example:

For the string { "[()]{}" }, the function should return true because every bracket is closed in the correct order. However, for the string { "[(])" }, the function should return false.

Instructions

  1. Implement the function isBalanced (or the equivalent in your language) which takes a string s that contains characters such as '(', ')', '{', '}', '[', and ']'.
  2. Use a stack to keep track of the opening brackets.
  3. Return true if the string is valid, otherwise return false.

Note: This problem is inspired by the significance of structure and order, much like historical events that have shaped our society. On February 18, we also remember the importance of organization in our traditions and celebrations.

Function Signature Example:

isBalanced(s: String) -> Boolean