Interview Question
Android EngineersCountry: United States
Interview Type: Phone Interview
You know what this can be an excellent question. I am not sure even interviewer thought to be that one. This actually is a palindrome question. Here is how.
The question is not to balance a parenthesis, which an be debatable coz any combination can give you balance expression.
So, how do you resolve this problem, is parse all string except braces and replace with common character. Ex. (a(b(c)de will become (x(x(x)xx.
Now, what it takes to convert this expression into palindrome is the question. I am sure may can now answer without further hints .
How would you know where the missing parenthesis go? In your example, (a(b(c)de)) is also a valid answer.
- Anonymous June 27, 2016If the parenthesis can go anywhere just count the number of "open" parenthesis that don't have a closing parenthesis and add them all at the end.