Can you provide me a logic for this question
Yeah so you just need to find the proper sequences for every index.
So first thing is that in the given string number of ‘(’ should be equal to ‘)’, otherwise no such index i exists.
Second thing is that if their number is equal how to count such indices i.
Lets denote the number of ‘(’ - ‘)’ as balance up until index i, so the number of indices i with minimum balance is the answer.( Try out a few examples)
Check this code for implementation https://ide.codingblocks.com/s/233213