For further actions, you may consider blocking this person and/or reporting abuse
For further actions, you may consider blocking this person and/or reporting abuse
Arjun Vijay Prakash -
Furkan GΓΆzΓΌkara -
Tadeu Barbosa -
Geoffrey Kim -
Top comments (6)
But what if the testcase is like 11110, the decreasing character is at index 3. Follow your solution then we have 11109 (not a tidy number, the correct answer is 9999). It seems that after decreasing the left part by 1, we also need to check those digits stand before the decreasing character again.
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!
Especially for the qualification round, where you have more time, I like the idea of your brute force algorithm as a unit test.
Thanks!
Indeed this is not a good solution for the next rounds, even if it could help you understand the problem.