When it comes to coding (or anything related to it) there's a rule I believe in with all my heart. It's the Thirty Minute Rule.
The rule is that if anyone gets stuck on something for more than 30 minutes, they should ask for help. By asking for help after 30 minutes it addresses the following things:
Whoever you can. Co-workers and collaborators are common. If they don't have the answer, online discussion forums, groups, or general social media are useful. This was the original use case for Stack Overflow.
Often, that's impossible. Many years ago I once spent several days trying to figure out how to package up something for deployment. When I finally got up the nerve to ask for help, I found out that critical details of our environment weren't in the group wiki, but handwritten in the system administrators' notebook. While that was an admittedly insane scenario, it embodies the fact that until I asked, there was no way I was ever going to accomplish my assigned task.
Had I asked for help in thirty minutes, I wouldn't have save myself a lot of frustration. I wouldn't have wasted several days of work.