You are perfectly right!
I just updated the gist with the fix (I forgot to make solve() recursive, that's the key!).
Btw, base on your idea then I found out a solution (edit a little bit):
We need to store the index of the first appearance of decreasing character, for example:
Your recursive solution is coded beautifully and easy to understand, thanks a lot!