Advice to New Programmers, pt3
It's okay to look at solutions
I've heard more than one senior engineer give the following advice:
As a general rule of thumb, you should give yourself a hard limit of 30 minutes to do a problem*. If at the 30 minute mark you're just not getting it, don't hesitate to look at the solution.
I definitely did not follow this advice as a beginner. In the early days, it wasn't uncommon for me to spend 2-3+ hours pulling my hair out on some of these problems. I felt like I had to come up with my own unique and original solutions. It was almost like a badge of honor to go through this pain. How else was I going to become a real programmer?
I now realize that this probably wasn't the best use of my time. Yes, it's true that at your first real programming job, you won't be able to "just look up the answer". But that doesn't mean that you shouldn't look at solutions when you're learning to code.
Don't get me wrong. Wanting to challenge yourself is a good thing. Just keep in mind that with all things, you can go too far. A rule like "I must solve this problem without looking at the answer", is an artificial constraint that could be hurting you more than it's helping you. The risk is that you're setting the bar to a height that's impossible to reach from where you are now. Also keep in mind that you're probably the worst judge of what you should be capable of as a beginner right now. The 30 minute cap off time is a simple heuristic to keep you in the happy medium place most of the time.
Stop feeling guilty
Looking at the solution is not "cheating" or even remotely bad. It's actually a necessary part of learning how to code. Simply put, you just don't have enough context yet as a beginner to solve most problems on your own. That's all. It doesn't have anything to do with your intelligence or capability. In fact, if you're a beginner and you're not looking at a lot of pre-existing solutions, I would say that your learning strategy is not very good.
I suspect that part of this is also changing your mindset around what it means to be a programmer. It's not about coming up with brilliant ideas all in your own head with no outside help. In fact, it may be quite the opposite. It's about knowing the history of this field. It's about knowing the solutions that have already been thought up by the people who came before you. After all, you can't forge new ground if you don't even know where you're coming from. And it is most definitely about collaboration and feeding off of the thoughts and energy of other people.
Are you the "no pain, no gain" type of person who refuses to look at the solution for hours and hours until you can't take it anymore and finally cave in? If you are, please stop this behavior right now! You'll only wear yourself out. Set a timer for 30 minutes and call it good after that. Learn from other people's solutions, and do it shamelessly. Not only will you learn faster, but you'll be a better programmer in the end for it.