Intermediate Level

Implement the method isBalancedBrackets that checks whether brackets are correctly nested.

Check matching and nesting for (), [], and {}. Other characters should be ignored.

The task is designed to test careful handling of edge cases, not only the most common input.

  • Return false when a closing bracket appears too early.
  • Return false when an opening bracket remains unmatched.
  • Return true only when every bracket pair is valid.
Example 1
Input:
s (string) = ({[]})
Return:
(boolean) true
Example 2
Input:
s (string) = ([)]
Return:
(boolean) false
Example 3
Input:
s (string) = a+(b*c)-{d/e}
Return:
(boolean) true

Push opening brackets on a stack and match every closing bracket against the latest opening bracket.

Run your code to see the result.