Skip to content
RED SAGSkills
easy15 ptsstacksstrings

Balanced Bracket String

A config linter needs to know whether the brackets in a string line up. The string s contains only the characters ()[]{}.

Return true if every opening bracket is closed by the same type of bracket in the correct order, otherwise false. The empty string is balanced.

Example 1

Input: s = "{[()()]}"
Output: true

Example 2

Input: s = "([)]"
Output: false
Explanation: The `[` is closed by `)` before its own `]`.

Constraints

  • 0 <= s.length <= 10^4
  • s consists only of ()[]{}
Hint 1

Push opening brackets onto a stack.

Hint 2

On a closing bracket, the top of the stack must be its matching opener.

Good practice for: Frontend Developer, Backend Developer, Full Stack Developer, Mobile App Developer, Game Developer, Automation Test Engineer, DevOps Engineer

Run checks your code on 2 sample tests. Submit runs all 8 tests, including hidden ones, and earns points. Use console.log to debug. Python's first run can take a few seconds while it starts.