CJCoding With Joseph
15free / daySign inCreate account

Balanced Brackets

The Stack class is given. Write balanced_brackets(text: str) -> bool that returns True when every opening bracket (, [ or { is closed by the matching closer in the right order, and False otherwise; characters that are not brackets are ignored. Push every opener; on a closer, the stack must not be empty and its popped top must be the matching opener (a dict such as pairs mapping each closer to its opener helps), otherwise return False. At the end the stack must be empty, so return what is_empty() says. Do NOT write a main block or any top-level test code; the tests construct the calls. Input: one line of text, possibly empty; the tests print the boolean your function returns.

Expected Output:

True

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
Data Structures & Algorithms
📥 Auto-Input:
([]{})\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.