Balanced Parentheses Check
Problem
Given a string containing bracket characters — (, ), {, }, [, ] — determine whether the brackets are balanced: every opening bracket has a matching closing bracket of the same type, and pairs are properly nested rather than interleaved.
Input / Output
- Input: a string
s. - Output: boolean —
trueif the brackets are balanced,falseotherwise.
Constraints
- Length up to ~10^5.
- The string may contain other characters to ignore, or may be guaranteed to hold only brackets — worth clarifying before coding.
Example
"{[()]}"→true."{[(])}"→false— correctly counted but improperly nested.- Tricky cases:
""→true;")("→false;"((("→false.
asked …