Question: Please use Java for the following question Brackets Matches Given a string of parentheses, check if the parentheses is valid and display the complete parentheses.
Please use Java for the following question
Brackets Matches
Given a string of parentheses, check if the parentheses is valid and display the complete parentheses.
For example:
Given a string value of "(("", it's a invalid parentheses because it's not complete, the complete parentheses should be "()()" because each "(" character shoud be mathced with a ")" closing bracket.
Sample input: "(()(("
Sample output should be : "()()()()".
Because only one set of parentheses is complete at index 1 and 2, so the other three "(" should have a ")" for each one of them.
Sample input: ")(()("
Sample output should be: "()()()()"
Since the first index has ")" so we should add a open bracket for it and index 1 has only "(" so add a close bracket to it and index 2 and 3 are a set of bracket so it's all set, and the last index should have a close bracket.
Sample input : "))(("
Sample output "()()()()"
Since all four indexes are missing parts of brackets so add brackets for them all.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
