Given the input inStr, give the boolean output out indicating whether all the parentheses are balanced.
Examples:
The string may include characters other than ( and ), but you should ignore them.
Incidentally, this problem was inspired from the Rosetta Code site. Why not create a few problems of your own by poking around the tasks at Rosetta Code?
can be solved without 'regexp'
A slightly more robust test might include a balanced equation starting with something other than an opening bracket.
Test 3 might be
inStr = '3*(z*(a-(x+3))/(y))';
Wrong solution.
it doesn't work in some cases not included in test suite. for example:
inStr = '(z*(a-(x+3))/(y)*z)';
Nice solution
Seems to fail for inStr='(' , '((', etc.
I admit this is cheating, but I think it also stresses the need for more tests in the suite. Also, not all the cases should necessarily be visible, so you can't adapt a solution like this.
This solution fails for the input ')()', i.e. it returns true when it should return false.
This solution fails for the input '(()', i.e. it returns true when it should return false.
This solution fails for the input '(()', i.e. it returns true when it should return false.
This entry is incorrect. It fails the simple case of:
isBalanced('(')
Find common elements in matrix rows
1073 Solvers
Getting the row and column location from a matrix
199 Solvers
733 Solvers
Given a 4x4 matrix, swap the two middle columns
490 Solvers
convert matrix to single column
233 Solvers