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
falsewhen a closing bracket appears too early. - Return
falsewhen an opening bracket remains unmatched. - Return
trueonly when every bracket pair is valid.
Push opening brackets on a stack and match every closing bracket against the latest opening bracket.