Remove Outermost Parentheses Problem

Remove Outermost Parentheses Problem — ExecCode Easy DSA Practice

Solve the Remove Outermost Parentheses problem on ExecCode. Free online easy DSA practice in String. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description You are given a valid parentheses string s, consider its primitive decomposition: s = P1 + P2 + ... Your task is to compute the required answer and return s after removing the outermost parentheses of every primitive string in the primitive decomposition of s. A valid parentheses string is either empty "", "(" + A + ")", or A + B, where A and B are valid parentheses strings, and + represents string concatenation. - For example, "", "()", "(())()", and "(()(()))" are all valid parentheses strings. A valid parentheses string s is primitive if it is nonempty, and there does not exist a way to split it into s = A + B, with A and B nonempty valid parentheses strings. + Pk, where Pi are primitive valid parentheses strings.

Examples

Input {"s": "(()())(())"}; Output ()()(). Input {"s": "(()())(())(()(()))"}; Output ()()()()(())

Constraints

1 <= s.length <= 10^5 s[i] is either '(' or ')'. s is a valid parentheses string.

Practice Remove Outermost Parentheses free on ExecCode. Browse DSA problems, topic map, and placement guides.