Description
A valid parentheses string is primitive if it cannot be split into two non-empty valid strings. Remove the outermost parentheses of every primitive string in the decomposition.
Examples
Input:
s = "(()())(())"Output:
"()()()"Explanation:
Remove outer parens.
Input:
s = "()()(())"Output:
"()()"Explanation:
The string has two primitive decompositions: "()" and "()(())". For the first "()", removing outer parentheses gives empty string. For "()(())", removing outer parentheses gives "()()". Combined result is "()()".
Input:
s = "((()))"Output:
"(())"Explanation:
This is a single primitive decomposition "((()))". The outermost parentheses are the first '(' and last ')'. Removing them leaves the inner nested parentheses "(())".
Constraints
- •
1 ≤ s.length ≤ 10⁵