I have tried a recursive solution as given in the question, but it did not work, so I did a little one cheat and copied the first 1000 terms in the sequence.
Honestly I don't know what else to do when the recursion returns a timeout on Python.
You need one array, one for loop and several lines of code to solve it and no cheating is needed. I did it in 4 languages with no problems. Recursion is mostly not the most efficient way to go. I had often problems with timeouts when using recursion here regardless of programming language.
Sonic thats why i didnt ask for the solution. My question specifically was about whether there is an issue with the testcases or not. considering recursive solution may cause test cases to fail is really a bummer.
oh, yeah, i did manage to get timeouts on the online editor as well. May be its the reason of failure. But, they should have known about it as well
i have reported it and lets see if they come back with a resolution
Michal Straka 🇨🇿 , thank you very much. I did use recursion and seems like its causing stack overflow for the system being used to run the test cases. I will use non-recursive approach but I still dont feel this is such a complex problem that cant be handled by recursion
So, I have managed to resolve it via Memoization technique in recursion. This allows to continue resolving a problem in its naturally recursive way while still avoiding any Stack Overflowing due to repeat calculation of the same subset again and again.
I haven't seen the solutions posted here either because I wanted to be fair. The only concerned i had was whether all the test cases were correct or not :)