The idea there are people out there that come into the challenge, understand it, and write a solution instantly without bugs, and it works perfectly the first time is just plain wrong.
The solutions you find for a given problem are written by people who have gone over the problem before, who understand the underpinnings of the problem, who know the language syntax, who know of all the “wrong” ways to do it (this is where some of the test cases come in). Odds are if your just starting out programming you don’t have any of that experience, and thus are stuck real quick.
Its not bad to look up answers, but you gotta ask yourself why do you need to look up the answers? Is it because you really are 100% stuck, didn’t know about the specific language syntax needed to solve it, was it because you had a bug in your code and it just didn’t work, or did you just give up after 5 or so minutes without trying anything?
Depending on the reason you should generally try to address it. Its one thing to not know something and need help, its another to “progress” with the curriculum without learning anything. Learning comes with failure and repetition, looking at the answer does mean there is an element of failure, but without repetition your stuck trying to memorize the answer, without actually learning anything.
I usually recommend doing 2 things when you find yourself looking up the answer.
- Go back a few lessons to review what you should already know until you get to a point where you remember and understand the problem.
- When your stuck, before looking up the answer directly, look up parts of the answer to help you along. This way you learn how to break down a problem, while still not trying to figure everything out all at once.
Neither of these are 100% the best path in terms of being a god level programmer where you can write perfect code from the start, but again this person doesn’t exist. The daily common-folk programmer is the one that is given a problem and fights their way through the problem, breaks it down, googles parts they don’t know or are unsure of, considers all stack overflow posts instead of blindly copy and pasting, and comes out learning a few things for the next time.
Don’t expect to succeed instantly, rather expect to succeed over time, and expect to learn the most during the time when stuff just isn’t working haha