Cody

# Problem 1303. Is the paranthesis sequence balanced ?

Solution 2829741

Submitted on 13 Aug 2020 by Ramesh Kumar V
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
assert(isequal(balance_parens('(((()))((())))'),1))

m = 14 count = 0 flag = 0 count = 1 count = 2 count = 3 count = 4 count = 3 count = 2 count = 1 count = 2 count = 3 count = 4 count = 3 count = 2 count = 1 count = 0 status_balanced = logical 1

2   Pass
assert(isequal(balance_parens('(()()())'),1))

m = 8 count = 0 flag = 0 count = 1 count = 2 count = 1 count = 2 count = 1 count = 2 count = 1 count = 0 status_balanced = logical 1

3   Pass
assert(isequal(balance_parens(['(()()()()()()()()()()()())']),1))

m = 26 count = 0 flag = 0 count = 1 count = 2 count = 1 count = 2 count = 1 count = 2 count = 1 count = 2 count = 1 count = 2 count = 1 count = 2 count = 1 count = 2 count = 1 count = 2 count = 1 count = 2 count = 1 count = 2 count = 1 count = 2 count = 1 count = 2 count = 1 count = 0 status_balanced = logical 1

4   Pass
assert(isequal(balance_parens('(()()()))))'),0))

m = 11 count = 0 flag = 0 count = 1 count = 2 count = 1 count = 2 count = 1 count = 2 count = 1 count = 0 flag = 1 count = -1 count = -2 count = -3 status_balanced = logical 0

5   Pass
assert(isequal(balance_parens('(()()(((((((((((()))))'),0))

m = 22 count = 0 flag = 0 count = 1 count = 2 count = 1 count = 2 count = 1 count = 2 count = 3 count = 4 count = 5 count = 6 count = 7 count = 8 count = 9 count = 10 count = 11 count = 12 count = 13 count = 12 count = 11 count = 10 count = 9 count = 8 status_balanced = logical 0

6   Pass
assert(isequal(balance_parens('))()())'),0))

m = 7 count = 0 flag = 0 flag = 1 count = -1 count = -2 count = -1 count = -2 count = -1 count = -2 count = -3 status_balanced = logical 0

7   Pass
assert(isequal(balance_parens('(()()()()((()))()()()(((()))))'),1))

m = 30 count = 0 flag = 0 count = 1 count = 2 count = 1 count = 2 count = 1 count = 2 count = 1 count = 2 count = 1 count = 2 count = 3 count = 4 count = 3 count = 2 count = 1 count = 2 count = 1 count = 2 count = 1 count = 2 count = 1 count = 2 count = 3 count = 4 count = 5 count = 4 count = 3 count = 2 count = 1 count = 0 status_balanced = logical 1

8   Pass
assert(isequal(balance_parens('((((()))))'),1))

m = 10 count = 0 flag = 0 count = 1 count = 2 count = 3 count = 4 count = 5 count = 4 count = 3 count = 2 count = 1 count = 0 status_balanced = logical 1

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!