Given string of parenthesis we have to do 2 kinds of operation:
- flip- changes the i-th parenthesis into the opposite one(left->right , right->left)
- check- if the string is a balanced parenthesis expression
length of the string is at max 30000.
No of operation to be performed is at max 100000.
what kind of data structure should one use to solve this kind of problem?
Is Segment Tree a suitable data structure?
If yes how should one use it?
Example
string = ()((
no of operation=4
- flip 4 {new string is ()()}
- check {string is balanced}
- flip 2{new string becomes ((()}
- check{string is not balanced}