Validate Bracket Sequence
Company: WeRide
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Take-home Project
Quick Answer: This question evaluates proficiency with stack data structures, string parsing and matching logic, and the ability to reason about algorithmic time and space complexity.
Constraints
- 0 <= len(s) <= 100000
- s consists only of the characters ()[]{}
Examples
Input: "()[]{}"
Expected Output: True
Explanation: Each opening bracket is matched by the correct closing bracket in a valid order.
Input: "([{}])"
Expected Output: True
Explanation: The brackets are properly nested, so every closing bracket matches the most recent opening bracket.
Input: "(]"
Expected Output: False
Explanation: The opening `(` is closed by `]`, which is the wrong type.
Input: "([)]"
Expected Output: False
Explanation: Although the counts match, the closing order is incorrect because `)` tries to close `(` before `[` is closed.
Input: "(("
Expected Output: False
Explanation: There are unmatched opening brackets remaining at the end.
Input: ""