Remove Outermost Parentheses

Basic String Manipulation DSA practice problem on Onlearn.

Difficulty: easy.

Topics: Binary Search Algorithm, String Manipulation, Loops, iterative algorithms, space complexity, array, divide and conquer, search space optimization, binary search, recursion, time complexity analysis.

Problem Statement A valid parentheses string is primitive if it is non empty, and there does not exist a way to split it into S = A+B, where A and B are non empty valid parentheses strings. Given a valid parentheses string s, consider its primitive decomposition: s = P1 + P2 + ... + Pk, where Pi are primitive valid parentheses strings. Return s after removing the outermost parentheses of every primitive string in the decomposition. Input Specification The input will consist of a single line containing a string s. s will be a valid parentheses string. Output Specification Output the modified string after removing the outermost parentheses of each primitive component. Constraints 1 <= s.length <= 10^5 s[i] is either '(' or ')'. Sample Test Cases Input: (()())(()) Output: ()()() Input: (()())(())(()(())) Output: ()()()()(()) Input: () Output: ""