Cody

# Problem 2653. Beauty of Parentheses

Solution 1959205

Submitted on 4 Oct 2019
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   Fail
str = '(()(()(()(()))))'; out = {'( )'; ' ()( ) '; ' ()( ) '; ' ()( ) '; ' () '} assert(isequal(braces(str),out))

out = 5×1 cell array {'( )'} {' ()( ) '} {' ()( ) '} {' ()( ) '} {' () '} ans = '(()' m = '(' ans = '(()' m = '(' ans = '(()' m = '(' ans = '(()' m = '(' ans = '(()' m = '(' ans = '(()' m = '(' ans = '(()' m = '(' ans = '(()' m = '(' ans = '(()' m = '(' ans = '(()' m = '(' ans = '(()' m = '(' ans = '(()' m = '(' ans = '(()' m = '(' ans = '(()' m = '(' ans = '(()' m = '(' ans = '(()' m = '('

Output argument "out" (and maybe others) not assigned during call to "braces". Error in Test1 (line 9) assert(isequal(braces(str),out))

2   Fail
str = '()'; % trivial test out = {'()'}; assert(isequal(braces(str),out))

Index exceeds the number of array elements (2). Error in braces (line 4) str(1:3) Error in Test2 (line 5) assert(isequal(braces(str),out))

3   Fail
str = '((((()))))'; out = {'( )'; ' ( ) '; ' ( ) '; ' ( ) '; ' () '} assert(isequal(braces(str),out))

out = 5×1 cell array {'( )'} {' ( ) '} {' ( ) '} {' ( ) '} {' () '} ans = '(((' m = '(' ans = '(((' m = '(' ans = '(((' m = '(' ans = '(((' m = '(' ans = '(((' m = '(' ans = '(((' m = '(' ans = '(((' m = '(' ans = '(((' m = '(' ans = '(((' m = '(' ans = '(((' m = '('

Output argument "out" (and maybe others) not assigned during call to "braces". Error in Test3 (line 9) assert(isequal(braces(str),out))

4   Fail
a = randi(10); str = ''; for i = 1:a str = [str '()']; end out = {str}; assert(isequal(braces(str),out))

ans = '()(' m = '()(' str = ')()()()()()()()' ans = ')()' ans = ')()' ans = ')()' ans = ')()' ans = ')()' ans = ')()' ans = ')()' ans = ')()' ans = ')()' ans = ')()' ans = ')()' ans = ')()' ans = ')()' ans = ')()' ans = ')()' ans = ')()' ans = ')()'

Output argument "out" (and maybe others) not assigned during call to "braces". Error in Test4 (line 7) assert(isequal(braces(str),out))

5   Fail
str = '()(((())))()'; out = {'()( )()'; ' ( ) '; ' ( ) '; ' () '} assert(isequal(braces(str),out))

out = 4×1 cell array {'()( )()'} {' ( ) '} {' ( ) '} {' () '} ans = '()(' m = '()(' str = '((())))()' ans = '(((' m = '(' ans = '(((' m = '(' ans = '(((' m = '(' ans = '(((' m = '(' ans = '(((' m = '(' ans = '(((' m = '(' ans = '(((' m = '(' ans = '(((' m = '(' ans = '(((' m = '(' ans = '(((' m = '(' ans = '(((' m = '('

Output argument "out" (and maybe others) not assigned during call to "braces". Error in Test5 (line 8) assert(isequal(braces(str),out))

6   Fail
a = randi(10); str = ''; for i = 1:a str = ['(' str ')']; end out = {}; for i = 1:a s = [32*ones(1,i-1) '(' 32*ones(1,2*a-2*i) ')' 32*ones(1,i-1)]; out = [out; s]; end assert(isequal(braces(str),out))

ans = '(((' m = '(' ans = '(((' m = '(' ans = '(((' m = '(' ans = '(((' m = '(' ans = '(((' m = '(' ans = '(((' m = '(' ans = '(((' m = '(' ans = '(((' m = '(' ans = '(((' m = '(' ans = '(((' m = '(' ans = '(((' m = '(' ans = '(((' m = '(' ans = '(((' m = '(' ans = '(((' m = '(' ans = '(((' m = '(' ans = '(((' m = '('

Output argument "out" (and maybe others) not assigned during call to "braces". Error in Test6 (line 14) assert(isequal(braces(str),out))