Algorithm based question. FInding balanced paranthesis
Anonymous
To find balanced parens, you need to set two parameters, the number of open parens must be greater than or equal the number of closed parens while parsing the string, and by the end, the number of open and closed parens must be equal. python solution: def balanced(parens): count_open = 0 count_closed = 0 for paren in parens: if paren == '(': count_open += 1 else count_close += 1 if count_open < count_closed: return False if count_open != count_closed return False return True
Check out your Company Bowl for anonymous work chats.