I have heard differing opinions on this. Some people say when you are stuck on a problem and the answer is available work on the problem for a while but if you get stuck and can’t figure it out go ahead and look at the answer. You are still learning by working through the problem with the answer. The other opinion is to hack away at the problem until you figure it out on your own. Which is the better way to learn and become a better developer?
I personally advise not to look at the answers before solving the problem first on your own, because it has never helped me. However, everyone learns differently and others can learn this way.
Here are some other forum threads where a similar question was asked.
This isn’t a direct response to your question, as I am more a proponent for not looking at others’ code when challenging myself, but I still thought it a little relevant when I came across it just now on Twitter: