Doubt in editorial

Sir this is the clean code

https://ideone.com/e.js/x7hb4I

its failing all the test cases, can you point out why ?

you are doing it recursively, then there is a chance of stack overflow due to too much recursive calls.
try doing same thing in loops