I had two long breaks between jobs. I've also had 4 different jobs in the last 5-ish years. So - I've had to do some prep every year. When I hit 1 year at any job - I start prepping again. I prepped probably 200 hours for the first job, 200 for the second, and then 100 for the third and fourth in the last 5-ish years. I pretty much never stay more than a year because it's the only way to get compensation and title to go up at all the companies I worked at.
I'd suggest always working on paper or whiteboard - never use a computer. (You have to emulate the environment) Set a timer for every problem. (1 hour max - aim for 45 minutes on medium/hard when starting out; lower it as you familiarize yourself with a subject) Start throwing data structures and algorithms at the problem (pattern matching them, basically). Solve it or don't. Learn something to take away from it. If you don't solve it, learn how to solve it, and where you were lacking. If you did solve it, be sure to check other solutions because sometimes yours is crap. Practice that thing you were lacking. (Needed to know BFS? Implement BFS from scratch 10 times using spaced repetition) If you're planning on 8 hour study sessions then focus on one type of problem at a time. (BFS, DFS, graph problems, tree problems, binary search, dynamic programming, etc.) Only do those kinds of problems in that session. Set it up like you would for a math class. You do one chapter in that session/day/week/whatever and proceed to do a few chapters (say a BFS chapter, a DFS chapter, and a binary search chapter)... Once you've done a few, give yourself a midterm covering the topics you learned. So give yourself like 2 DFS, 2 BFS, and 2 binary search problems and see if you can solve them in a timed environment. If you rocked the midterm then proceed on to do more chapters and more midterms. If you didn't then relearn those subjects before moving on. Finally, when you feel like you've learned everything then give yourself a final exam to see if you remember everything and can still do it right.
Basically - treat it like a math class. It's not just memorization (you need to memorize the strategies, that's for sure - you need to be really fast at implementing BFS, DFS, binary search, etc. That should be wrote memorization but with a deep understanding).
When I try to solve a problem I generally see the output needed and construct code to get the pattern with a lot of trail and error. I am not sure if I can scale with this. If I am fresh and in flow I can come up with good solutions. If not and I am nervous then I will have trouble solving something as simple as fibonacci.
I sometimes have trouble doing pattern matching where I get confused if the problem is changed slightly and is made tricky. I think this is because I am trying to be too specific with the match and not seeing a generic picture.
Can you suggest how a person with a job can practice so thoroughly? 8 hour sessions everyday is tough maybe on weekends but still is sometimes difficult.
I'd suggest always working on paper or whiteboard - never use a computer. (You have to emulate the environment) Set a timer for every problem. (1 hour max - aim for 45 minutes on medium/hard when starting out; lower it as you familiarize yourself with a subject) Start throwing data structures and algorithms at the problem (pattern matching them, basically). Solve it or don't. Learn something to take away from it. If you don't solve it, learn how to solve it, and where you were lacking. If you did solve it, be sure to check other solutions because sometimes yours is crap. Practice that thing you were lacking. (Needed to know BFS? Implement BFS from scratch 10 times using spaced repetition) If you're planning on 8 hour study sessions then focus on one type of problem at a time. (BFS, DFS, graph problems, tree problems, binary search, dynamic programming, etc.) Only do those kinds of problems in that session. Set it up like you would for a math class. You do one chapter in that session/day/week/whatever and proceed to do a few chapters (say a BFS chapter, a DFS chapter, and a binary search chapter)... Once you've done a few, give yourself a midterm covering the topics you learned. So give yourself like 2 DFS, 2 BFS, and 2 binary search problems and see if you can solve them in a timed environment. If you rocked the midterm then proceed on to do more chapters and more midterms. If you didn't then relearn those subjects before moving on. Finally, when you feel like you've learned everything then give yourself a final exam to see if you remember everything and can still do it right.
Basically - treat it like a math class. It's not just memorization (you need to memorize the strategies, that's for sure - you need to be really fast at implementing BFS, DFS, binary search, etc. That should be wrote memorization but with a deep understanding).