← DiffPush

Remove outer parenthesis

Baseline Strings · Easy O(n) · O(n)

Stripping Envelope Markers Off Packet Frames

A message broker chops a transmission stream into primitive frames, and every frame is wrapped in exactly one outer pair of framing markers. Before payloads are forwarded downstream, that outermost wrapper must be peeled off each frame so only the inner content is shipped. Given the raw marker stream, emit it with every frame's outermost pair removed.

Input: A string s consisting of '(' and ')' characters that forms a valid, balanced parentheses sequence.

Output: The string s with the outermost parentheses of every primitive component deleted; content that sat deeper inside is preserved in order.

Constraints

Examples

Example 1

Input: {"s":"(()())(())"}
Output: "()()()"
Two primitive frames sit back to back; peeling each outer wrapper leaves their inner contents concatenated.

Example 2

Input: {"s":"(()())(())(()(()))"}
Output: "()()()()(())"
The final frame carries a nested inner pair that survives, while only its outermost wrapper is stripped.

Solve this in your browser →

Also on LeetCode ↗