Implement a function string balanceParanthesis(string s); which given a string s consisting of some parenthesis returns a string s1 in which parenthesis are balanced and differences between s and s1 are minimum. Eg - "(ab(xy)u)2)" -> "(ab(xy)u)2" ")))(((" -> ""
Anonym
All we need to do is to delete unnecessary parenthesis. every time we encounter a ')' which has no previous '(' to match with, delete. delete every '(' left when we finished reading the string s.