Can anyone help me out:
Your code fails here:
3
<<<><<>>>
<<<><>>><<>>><>
<<>>><><><
Your Output:
8
8
4
Actual Output
0
12
4
Click to view
You can solve this in much easier way. Just keep a variable unbalance. If s[i]==’<’ unbalance+=1 else unbalance-=1. If unbalance becomes equal to 0 at index i, update answer to i+1. Else if unbalance becomes <0 break. Here is my implementation for the same.