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 — true if the brackets are balanced, false otherwise.

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 …
LeaderboardSalaryAccount