+ 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.

26th Jan 2020, 3:55 AM
sharpdesigner
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.
26th Jan 2020, 4:37 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 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.
26th Jan 2020, 2:22 PM
Michal Straka
Michal Straka - avatar
+ 2
many did. Which kind of answer do you exoect?
26th Jan 2020, 4:27 AM
Oma Falk
Oma Falk - avatar
+ 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.
27th Jan 2020, 4:40 AM
sharpdesigner
+ 2
sharpdesigner that's OK then 👍
27th Jan 2020, 4:40 AM
Sonic
Sonic - avatar
+ 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
26th Jan 2020, 5:16 AM
Mihai Apostol
Mihai Apostol - avatar
+ 1
Some moderators have discouraged discussing code coach challenges in Q&A.
27th Jan 2020, 4:31 AM
Sonic
Sonic - avatar
0
jind?
26th Jan 2020, 4:28 AM
sharpdesigner
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
26th Jan 2020, 4:56 AM
sharpdesigner
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
26th Jan 2020, 5:34 PM
sharpdesigner
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 :)
30th Jan 2020, 4:44 PM
sharpdesigner