Google | Phone | Remove Enclosing Bracket
Anonymous User
3714

I recently had Phone interview ,
Question -
Given s String with some characters and brackets. Return String after removing Enclosing Brackets. Also provide a set of test cases for the problem
For Example:
(((a))) -> a
((ab)(bc))d -> ((ab)(bc))d
() => ""
((a)(bcd)(e)) -> (a)(bcd)(e)
solution
Gave a solution with binary search, complexity : O(nLog(n))
for example - (((a)(bcd)(e))) -> (a)(bcd)(e)
Count the no of outermost bracket eligible for removal. In this case it is n = 3.
Now , low = 1, high = 3 , do a binary search .
for every mid, check if string is valid, choose to right part. If not, choose left.
Finally return ans.
Interviewer was satisfied with approach.

Any other solution you guys can think of?

Comments (17)