Your question is Check Balanced Parentheses. 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.
A Comcast Xfinity Stream interface receives configuration expressions containing grouping symbols. Write a function that determines whether every bracket is correctly matched and nested.
The input may contain parentheses (), square brackets [], and curly braces {}. Non-bracket characters, including letters, digits, spaces, and punctuation, must be ignored. A string is balanced only when every opening bracket has the correct closing bracket in last-in, first-out order.
Implement is_balanced(s), which accepts a string s and returns a boolean:
True if all brackets are properly matched and nested.False if a closing bracket has no matching opener, if bracket types are mismatched, or if any opener remains unmatched.def is_balanced(s):