Remove Outermost Parentheses
A valid parentheses string is a non-empty string that is either: - "()" (a single pair), or - A + B where A and B are valid parentheses strings, or - (A)…
A valid parentheses string is a non-empty string that is either: - `"()"` (a single pair), or - `A + B` where `A` and `B` are valid parentheses strings, or - `(A)` where `A` is a valid parentheses string. A **primitive** decomposition of a valid parentheses string `s` is a decomposition of `s` into primitive valid parentheses strings (i.e. strings that cannot themselves be split into two non-empty valid parentheses strings). Remove the outermost parentheses of every primitive in the primitive decomposition of `s`. Indexing is **0-based**. **Example:** `"(()())(())"` has two primitives: `"(()())"` and `"(())"`. After removing the outer pair of each: `"()()"` + `"()"` = `"()()()"`.
- `1 <= s.length <= 10^5` - `s` consists only of characters `(` and `)`. - `s` is a valid parentheses string. - The interactive visualizer accepts `2 <= s.length <= 40`; longer valid judge inputs are execution-only.
Example 1: input s = "(()())(())"; output ()()(). Two primitives "(()())" and "(())" stripped to "()()" and "()" respectively, concatenated.
Example 2: input s = "(())()"; output (). Two primitives "(())" and "()" stripped to "()" and "" respectively, concatenated.
Category: Strings. Topic: strings. Difficulty: Easy. Patterns: string-processing.