← Programming questions
Easy / PYTHON

Balanced Brackets

strings · stacks 12 minute study target

Not completed

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

Example 1

Arguments

['([]){}']

Expected return

True
Example 2

Arguments

['([)]']

Expected return

False
Example 3

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.

valid_parentheses.pyPython 3.12

Drafts are saved to your account, not to shared browser storage.

Sign in to submit code and save progress.

Results

Your results will appear here.

Hidden tests reveal only their pass/fail status, never their inputs or expected outputs. Runtime is observed wall time—not an inferred complexity class.

© 2026 EverythingQuant. All Rights Reserved.