Check That a String of Three Bracket Types Is Properly Nested
Company: Oracle
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: Decide whether a string made of round, square and curly brackets is properly nested, meaning every closing bracket matches the most recently opened bracket of the same type and nothing is left open. Tests careful handling of nesting order, crossing pairs and unmatched brackets at either end.
Constraints
- 1 <= len(s) <= 10^4
- Every character of s is one of (, ), [, ], {, }.
- No numeric value can exceed 2^31-1; the only input is the string.
Examples
Input: ('(',)
Expected Output: False
Explanation: Minimum length: a lone opener is never closed.
Input: (']',)
Expected Output: False
Explanation: Minimum length: a lone closer arrives while nothing is open.
Hints
- When a closing bracket arrives, the rules allow exactly one earlier bracket to be its partner: the most recently opened one that is still open.
- As you read left to right, decide what you must remember about brackets that are still open, and in which order you will need to get them back.
- Besides a type mismatch, a string fails in two more ways: a closer arrives when nothing is open, or something is still open when the string ends.