Given a string containing only paranthesis ')' or '(', find the minimum number of swaps (need not be adjacent characters) to balance the string. If it's not possible to balance, return -1.
For eg: ))((
Ans - 1, Swap first and last bracket -> ()()
eg: (()())
Ans - 0
Wasn't able to come up with even a brute force solution. Could someone share the solution with the time complexity?