{"id":"c735763c-1cc5-4494-8109-aac670f046a1","name":"Remove Outermost Parentheses","description":"1. You are given a valid parentheses string in form of A+B+C... where A, B and C are valid primitive strings.\r\n2. A primitive string is a valid parentheses string which cant is split in s = x+y, with x and y nonempty valid parentheses strings.\r\n3. You have to remove the outermost parentheses from all primitive strings.\r\n\r\nExample \"(()())(())\" = \"(()())\" + \"(())\".\r\nremoving outermost parentheses from \"(()())\" and \"(())\" will result in ()()().","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1. s.length &lt;= 10000\r\n2. s[i] is \"(\" or \")\"\r\n3. s is a valid parentheses string","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\nstring removeOuterParentheses(string s) \n {\n //Write your code here\n }\n \n int main(int argc, char **argv)\n{ \n string S;\n cin>>S;\n string ans = removeOuterParentheses(S); \n if(ans.length()==0) cout<<\" \";\n else cout<<ans;\n\n return 0;\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n public static String removeOuterParentheses(String s) {\r\n // write your code here\r\n }\r\n\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader read = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n String result = removeOuterParentheses(read.readLine());\r\n System.out.println(result);\r\n }\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"(()())(())","sampleOutput":"()()()\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"8c6022a5-8654-4226-918f-8110af738bd4","name":"Stacks For Intermediate","slug":"stacks-for-intermediate-688","type":0},{"id":"6f03c096-7fc7-4285-bada-e8247546b0d6","name":"Remove Outermost Parentheses","slug":"remove-outermost-parentheses","type":1}],"next":{"id":"34283ac9-d7ed-49f9-af35-845fa890ade2","name":"Remove Outermost Parentheses Easy MCQ","type":0,"slug":"remove-outermost-parentheses-easy-mcq"},"prev":{"id":"44a3db7e-8dfb-4953-ba4e-a5260c3ce3c9","name":"Minimum add to make parentheses valid","type":3,"slug":"minimum-add-to-make-parentheses-valid"}}}

Remove Outermost Parentheses

1. You are given a valid parentheses string in form of A+B+C... where A, B and C are valid primitive strings. 2. A primitive string is a valid parentheses string which cant is split in s = x+y, with x and y nonempty valid parentheses strings. 3. You have to remove the outermost parentheses from all primitive strings. Example "(()())(())" = "(()())" + "(())". removing outermost parentheses from "(()())" and "(())" will result in ()()().

{"id":"c735763c-1cc5-4494-8109-aac670f046a1","name":"Remove Outermost Parentheses","description":"1. You are given a valid parentheses string in form of A+B+C... where A, B and C are valid primitive strings.\r\n2. A primitive string is a valid parentheses string which cant is split in s = x+y, with x and y nonempty valid parentheses strings.\r\n3. You have to remove the outermost parentheses from all primitive strings.\r\n\r\nExample \"(()())(())\" = \"(()())\" + \"(())\".\r\nremoving outermost parentheses from \"(()())\" and \"(())\" will result in ()()().","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1. s.length &lt;= 10000\r\n2. s[i] is \"(\" or \")\"\r\n3. s is a valid parentheses string","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\nstring removeOuterParentheses(string s) \n {\n //Write your code here\n }\n \n int main(int argc, char **argv)\n{ \n string S;\n cin>>S;\n string ans = removeOuterParentheses(S); \n if(ans.length()==0) cout<<\" \";\n else cout<<ans;\n\n return 0;\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n public static String removeOuterParentheses(String s) {\r\n // write your code here\r\n }\r\n\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader read = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n String result = removeOuterParentheses(read.readLine());\r\n System.out.println(result);\r\n }\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"(()())(())","sampleOutput":"()()()\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"8c6022a5-8654-4226-918f-8110af738bd4","name":"Stacks For Intermediate","slug":"stacks-for-intermediate-688","type":0},{"id":"6f03c096-7fc7-4285-bada-e8247546b0d6","name":"Remove Outermost Parentheses","slug":"remove-outermost-parentheses","type":1}],"next":{"id":"34283ac9-d7ed-49f9-af35-845fa890ade2","name":"Remove Outermost Parentheses Easy MCQ","type":0,"slug":"remove-outermost-parentheses-easy-mcq"},"prev":{"id":"44a3db7e-8dfb-4953-ba4e-a5260c3ce3c9","name":"Minimum add to make parentheses valid","type":3,"slug":"minimum-add-to-make-parentheses-valid"}}}
plane

Editor


Loading...

Remove Outermost Parentheses

easy

1. You are given a valid parentheses string in form of A+B+C... where A, B and C are valid primitive strings. 2. A primitive string is a valid parentheses string which cant is split in s = x+y, with x and y nonempty valid parentheses strings. 3. You have to remove the outermost parentheses from all primitive strings. Example "(()())(())" = "(()())" + "(())". removing outermost parentheses from "(()())" and "(())" will result in ()()().

Constraints

1. s.length <= 10000 2. s[i] is "(" or ")" 3. s is a valid parentheses string

Format

Input

Input is managed for you

Output

Output is managed for you

Example

Sample Input

(()())(())

Sample Output

()()()

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode