Challenge
Check whether a string of round, square and curly brackets is properly nested. Every closing bracket must match the most recent unmatched opening bracket, and no opening bracket may remain at the end. Return a Boolean, not 0/1 or a string.
Input and output contract
0 ≤ length ≤ 60,000. Only the six characters ()[]{} appear. The empty string is valid.
All tests follow this contract. You do not need to validate malformed input. Return the requested result from valid_parentheses; printed output is not your answer. Standard-library tools are allowed. Implement your solution in Python 3.12.
Target complexity: O(n) time; O(n) auxiliary space
Return values are checked by type. Use the exact function name. Print output is not your answer. Tests have time and memory limits.
Public examples
Arguments
['([]){}']Expected return
True
Arguments
['([)]']
Expected return
False
Arguments
['']
Expected return
True
Hint
The next closing bracket must match the opening bracket most recently placed on a stack.
The worked solution unlocks after completion, or with Premium access.