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!
We’re a place for programmers to stay up-to-date, learn new skills, and share ideas.
We’ll never post without your permission.