Check Balanced Parentheses

Advanced

Check Balanced Parentheses

In this challenge, you're tasked with helping ensure that a set of parentheses () in a string are properly balanced! Balanced parentheses mean that each opening parenthesis has a matching closing parenthesis and they are well-nested.

For example:

  • "(())" is balanced.
  • "(()())" is balanced.
  • "(()" is not balanced (one opening parenthesis without a match).
  • "())(" is not balanced (the order is incorrect).

Your task is to write a function check_balanced_parentheses that returns True if the parentheses in the input string are balanced, and False otherwise. Here's how it works:

check_balanced_parentheses("(())") # returns True check_balanced_parentheses("(()") # returns False check_balanced_parentheses("()()") # returns True check_balanced_parentheses("())(") # returns False

Think about using a counter to keep track of the opening and closing parentheses!

Have fun and happy coding!

Geek
Inputs

Arg 1:

"(())"
Expected Output
true
Actual Output
Check Balanced Parentheses [advanced] | Coding for Kids