Cody

Problem 80. Test for balanced parentheses

Solution 2263335

Submitted on 8 May 2020 by Nathan Choi
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))

op = 1 cp = 2 on = 1 cn = 1 op = 1×0 empty double row vector out = logical 1

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

op = [] cp = 1 on = 0 cn = 1

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

op = 1 4 7 14 cp = 11 12 16 17 on = 4 cn = 4 op = 1 4 7 op = 1 4 op = 1 op = 1×0 empty double row vector out = logical 1

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

op = 2 cp = 1 on = 1 cn = 1 op = 1×0 empty double row vector out = logical 0

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

op = 1 4 cp = 3 8 on = 2 cn = 2 op = 1 op = 1×0 empty double row vector out = logical 1

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

op = 1×0 empty double row vector cp = 3 on = 0 cn = 1

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

op = 2 cp = 1 3 on = 1 cn = 2

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

op = 1 2 cp = 3 on = 2 cn = 1

Suggested Problems

More from this Author95

Community Treasure Hunt

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

Start Hunting!