Your question is Validating Balanced Brackets. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
AI-first Technology's prompt editor must reject prompts containing incorrectly matched brackets before they are sent for processing. Given a string representing a prompt, determine whether every bracket is correctly opened, closed, and nested.
The supported bracket pairs are (), [], and {}. All other characters, including letters, digits, whitespace, and operators, must be ignored. A prompt is balanced only when each closing bracket matches the most recently opened bracket and no brackets remain unclosed.
Implement is_balanced(expression).
expression, a string of length n containing printable characters.True if all brackets are balanced and properly nested; otherwise return False.def is_balanced(expression):