Remove Outermost Parentheses
s is a valid parentheses string. Split it into the smallest possible balanced pieces, for example (()())(()) is (()()) followed by (()). Remove the outermost pair of parentheses from each piece and return what is left joined together.
Example 1
s "(()())(())"
returns "()()()"
Pieces (()()) and (()) become ()() and (), giving ()()().
Example 2
s "()()"
returns ""
Each piece () becomes empty.
Constraints
2 <= len(s) <= 100sis a valid parentheses string of(and)
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.