Approach :
Push (a) :“P” times
Push (b): “P” times
we now have “2*P” element in stack ,Now Remove 2 element for one “a” .
Dear @jugnu1337,
In your approach you completely ignore “b” ,which can lead to some problem like this :
string: aabaa (this string should not be accepted but it will be accepted by your logic ).