Cody

# Problem 80. Test for balanced parentheses

Solution 2647631

Submitted on 3 Jul 2020
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
inStr = '()'; out_correct = true; assert(isequal(isBalanced(inStr),out_correct))

out = logical 1

2   Pass
inStr = ')'; out_correct = false; assert(isequal(isBalanced(inStr),out_correct))

out = logical 0

3   Fail
inStr = '(z*(a-(x+3))/(y))'; out_correct = true; assert(isequal(isBalanced(inStr),out_correct))

Operands to the || and && operators must be convertible to logical scalar values. Error in isBalanced (line 6) if length(ind1)==length(ind2) && (ind2>ind1) Error in Test3 (line 3) assert(isequal(isBalanced(inStr),out_correct))

4   Pass
inStr = ')('; out_correct = false; assert(isequal(isBalanced(inStr),out_correct))

out = logical 0

5   Fail
inStr = '(x)(x-y)'; out_correct = true; assert(isequal(isBalanced(inStr),out_correct))

Operands to the || and && operators must be convertible to logical scalar values. Error in isBalanced (line 6) if length(ind1)==length(ind2) && (ind2>ind1) Error in Test5 (line 3) assert(isequal(isBalanced(inStr),out_correct))

6   Pass
inStr = ':-)'; out_correct = false; assert(isequal(isBalanced(inStr),out_correct))

out = logical 0

7   Pass
inStr = ')()'; out_correct = false; assert(isequal(isBalanced(inStr),out_correct))

out = logical 0

8   Pass
inStr = '(()'; out_correct = false; assert(isequal(isBalanced(inStr),out_correct))

out = logical 0

### Community Treasure Hunt

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

Start Hunting!