+ 3
Have anyone managed to solve Hofstadter's Q-Sequence codecoach challenge?
Well, I am sure the solution i have had is correct and all the sequences input matches the sequence (googled the sequence). But, I kept failing test cases 3-6 which are all hidden. I used C# for it.
11 Answers
+ 6
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.
+ 5
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.
+ 2
many did.
Which kind of answer do you exoect?
+ 2
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.
+ 2
sharpdesigner that's OK then 👍
+ 1
sharpdesigner 🌟(Pro)metheus 🇸🇬 Check out Alexandr's idea from this post, works like a charm, no need for recursion.
Edit. forgot to link post
https://www.sololearn.com/Discuss/2113151/?ref=app
+ 1
Some moderators have discouraged discussing code coach challenges in Q&A.
0
jind?
0
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
0
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
0
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 :)