{"id":"9437468f-fd44-470c-b9e7-a2f5aad46bf4","name":"Remove Invalid Parenthesis","description":"1. You are given a string, which represents an expression having only opening and closing parenthesis.\r\n2. You have to remove minimum number of parenthesis to make the given expression valid.\r\n3. If there are multiple answers, you have to print all of them.\r\n\r\nNote -> Check out the question video and write the recursive code as it is intended without changing signature. The judge can't \r\n force you but intends you to teach a concept.","inputFormat":"A string containing only opening and closing parenthesis","outputFormat":"Print all the Valid expressions.\r\nCheck the sample ouput and question video.","constraints":"1 &lt;= length of string &lt;= 20","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static void solution(String str, int minRemoval, HashSet<String> ans) {\r\n\t\t//write your code here\r\n\t}\r\n\r\n\tpublic static int getMin(String str){\r\n\t\t//write your code here\r\n\t\treturn 0;\r\n\t}\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tString str = scn.next();\r\n\t\tsolution(str, getMin(str),new HashSet<>());\r\n\t}\r\n\t\t\r\n}"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"hard","sampleInput":"()())()","sampleOutput":"(())()\r\n()()()\r\n","questionVideo":"https://www.youtube.com/embed/Cbbf5qe5stw?end=107","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":"082986ae-d618-4a59-9ab3-6d79056679a4","name":"Recursion and Backtracking For Intermediate","slug":"recursion-and-backtracking-for-intermediate-330","type":0},{"id":"435efa26-e44e-45be-a98e-3eae7398022e","name":"Remove Invalid Parenthesis","slug":"remove-invalid-parenthesis","type":1}],"next":{"id":"57b72ce7-7ba7-4933-a138-3d5ce7660699","name":"Remove Invalid Parenthesis MCQ","type":0,"slug":"remove-invalid-parenthesis-mcq"},"prev":{"id":"6bb4b4c6-1bea-4275-bc64-111fe5d16e14","name":"Word break-1 MCQ","type":0,"slug":"word-break-1-mcq"}}}

Remove Invalid Parenthesis

1. You are given a string, which represents an expression having only opening and closing parenthesis. 2. You have to remove minimum number of parenthesis to make the given expression valid. 3. If there are multiple answers, you have to print all of them. Note -> Check out the question video and write the recursive code as it is intended without changing signature. The judge can't force you but intends you to teach a concept.

{"id":"9437468f-fd44-470c-b9e7-a2f5aad46bf4","name":"Remove Invalid Parenthesis","description":"1. You are given a string, which represents an expression having only opening and closing parenthesis.\r\n2. You have to remove minimum number of parenthesis to make the given expression valid.\r\n3. If there are multiple answers, you have to print all of them.\r\n\r\nNote -> Check out the question video and write the recursive code as it is intended without changing signature. The judge can't \r\n force you but intends you to teach a concept.","inputFormat":"A string containing only opening and closing parenthesis","outputFormat":"Print all the Valid expressions.\r\nCheck the sample ouput and question video.","constraints":"1 &lt;= length of string &lt;= 20","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static void solution(String str, int minRemoval, HashSet<String> ans) {\r\n\t\t//write your code here\r\n\t}\r\n\r\n\tpublic static int getMin(String str){\r\n\t\t//write your code here\r\n\t\treturn 0;\r\n\t}\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tString str = scn.next();\r\n\t\tsolution(str, getMin(str),new HashSet<>());\r\n\t}\r\n\t\t\r\n}"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"hard","sampleInput":"()())()","sampleOutput":"(())()\r\n()()()\r\n","questionVideo":"https://www.youtube.com/embed/Cbbf5qe5stw?end=107","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":"082986ae-d618-4a59-9ab3-6d79056679a4","name":"Recursion and Backtracking For Intermediate","slug":"recursion-and-backtracking-for-intermediate-330","type":0},{"id":"435efa26-e44e-45be-a98e-3eae7398022e","name":"Remove Invalid Parenthesis","slug":"remove-invalid-parenthesis","type":1}],"next":{"id":"57b72ce7-7ba7-4933-a138-3d5ce7660699","name":"Remove Invalid Parenthesis MCQ","type":0,"slug":"remove-invalid-parenthesis-mcq"},"prev":{"id":"6bb4b4c6-1bea-4275-bc64-111fe5d16e14","name":"Word break-1 MCQ","type":0,"slug":"word-break-1-mcq"}}}
plane

Editor


Loading...

Remove Invalid Parenthesis

hard

1. You are given a string, which represents an expression having only opening and closing parenthesis. 2. You have to remove minimum number of parenthesis to make the given expression valid. 3. If there are multiple answers, you have to print all of them. Note -> Check out the question video and write the recursive code as it is intended without changing signature. The judge can't force you but intends you to teach a concept.

Constraints

1 <= length of string <= 20

Format

Input

A string containing only opening and closing parenthesis

Output

Print all the Valid expressions. Check the sample ouput and question video.

Example

Sample Input

()())()

Sample Output

(())() ()()()

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode