Spending Time On a Problem

How do you guys go through problems when practicing? I usually go 2 hrs without looking at the answer, trying to solve it, and then looking at the solution. However, I found this ineffective and not very helpful. What do you guys suggest I do or what do you do when you go through a problem? What’s the right way to approach problems?