That depends on your level as a programmer. A real beginner shouldn't spend a long time on it as s/he will just be wasting time and becoming frustrated. Someone with more experience might spend more time on it because they have more things to think over and more ideas to try.
What is more important is what happens AFTER looking up a solution. You have to be analytical and look at the solution. How does it work? How is it different from your attempt(s)? Why is it better than any attempt you made? And so on. This is difficult for a beginner, but you will get better.