{"id":"1eb97cc6-cd79-479e-bbaa-600f4f0a3698","name":"Reverse Substrings Between Each Pair Of Parentheses","description":"1: You are given a string s that consists of lower case English letters and brackets. \r\n2: Reverse the strings in each pair of matching parentheses, starting from the innermost one.\r\n3: Your result should not contain any brackets.\r\n\r\nExample\r\n(abcd) -> dcba\r\n(u(love)i) -> iloveu\r\n(gni(pc(do))ep) -> pepcoding","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1: 0 &lt;= s.length &lt;= 2000\r\n2: s only contains lower case English characters and parentheses\r\n3: It's guaranteed that all parentheses are balanced.","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\n\n string reverseParentheses(string s)\n{ \n // write your code here\n}\nint main(){ \n string s;\n cin>>s;\n string result = reverseParentheses(s);\n cout<< result<<endl;\n return 0;\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n public static String reverseParentheses(String s) {\r\n Stack<Integer> st = new Stack<>();\r\n return null;\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 = reverseParentheses(read.readLine());\r\n System.out.println(result);\r\n \r\n }\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"(gni(pc(do))ep)","sampleOutput":"pepcoding\r\n","questionVideo":"https://www.youtube.com/embed/4a4bspKyOH8","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":"e9af7ecc-6298-49c5-aa0e-9783386a6888","name":"Reverse Substrings Between Each Pair Of Parentheses","slug":"reverse-substrings-between-each-pair-of-parentheses","type":1}],"next":{"id":"4798b4b5-4428-4a39-9c9e-a583d254b3a1","name":"Reverse Substrings Between Each Pair Of Parentheses Medium MCQ","type":0,"slug":"reverse-substrings-between-each-pair-of-parentheses-medium-mcq"},"prev":{"id":"95599df9-70fb-414e-89c7-bb72a65d6341","name":"Score of Parentheses","type":3,"slug":"score-of-parentheses"}}}

Reverse Substrings Between Each Pair Of Parentheses

1: You are given a string s that consists of lower case English letters and brackets. 2: Reverse the strings in each pair of matching parentheses, starting from the innermost one. 3: Your result should not contain any brackets. Example (abcd) -> dcba (u(love)i) -> iloveu (gni(pc(do))ep) -> pepcoding

{"id":"1eb97cc6-cd79-479e-bbaa-600f4f0a3698","name":"Reverse Substrings Between Each Pair Of Parentheses","description":"1: You are given a string s that consists of lower case English letters and brackets. \r\n2: Reverse the strings in each pair of matching parentheses, starting from the innermost one.\r\n3: Your result should not contain any brackets.\r\n\r\nExample\r\n(abcd) -> dcba\r\n(u(love)i) -> iloveu\r\n(gni(pc(do))ep) -> pepcoding","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1: 0 &lt;= s.length &lt;= 2000\r\n2: s only contains lower case English characters and parentheses\r\n3: It's guaranteed that all parentheses are balanced.","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\n\n string reverseParentheses(string s)\n{ \n // write your code here\n}\nint main(){ \n string s;\n cin>>s;\n string result = reverseParentheses(s);\n cout<< result<<endl;\n return 0;\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n public static String reverseParentheses(String s) {\r\n Stack<Integer> st = new Stack<>();\r\n return null;\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 = reverseParentheses(read.readLine());\r\n System.out.println(result);\r\n \r\n }\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"(gni(pc(do))ep)","sampleOutput":"pepcoding\r\n","questionVideo":"https://www.youtube.com/embed/4a4bspKyOH8","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":"e9af7ecc-6298-49c5-aa0e-9783386a6888","name":"Reverse Substrings Between Each Pair Of Parentheses","slug":"reverse-substrings-between-each-pair-of-parentheses","type":1}],"next":{"id":"4798b4b5-4428-4a39-9c9e-a583d254b3a1","name":"Reverse Substrings Between Each Pair Of Parentheses Medium MCQ","type":0,"slug":"reverse-substrings-between-each-pair-of-parentheses-medium-mcq"},"prev":{"id":"95599df9-70fb-414e-89c7-bb72a65d6341","name":"Score of Parentheses","type":3,"slug":"score-of-parentheses"}}}
plane

Editor


Loading...

Reverse Substrings Between Each Pair Of Parentheses

medium

1: You are given a string s that consists of lower case English letters and brackets. 2: Reverse the strings in each pair of matching parentheses, starting from the innermost one. 3: Your result should not contain any brackets. Example (abcd) -> dcba (u(love)i) -> iloveu (gni(pc(do))ep) -> pepcoding

Constraints

1: 0 <= s.length <= 2000 2: s only contains lower case English characters and parentheses 3: It's guaranteed that all parentheses are balanced.

Format

Input

Input is managed for you

Output

Output is managed for you

Example

Sample Input

(gni(pc(do))ep)

Sample Output

pepcoding

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode