In fields like chess, math, and computer science, you need to do the problems to learn. You cannot learn just by watching a lecture. It is a skill that one must cultivate via doing.
But the question is, how much should you spend on a problem that you cannot solve?
One school of thought is that you keep at that problem until you can solve it by yourself. It seems to make sense. If you put enough effort, you will discover the solution. Or find a novel one. Unfortunately you may not find a solution, so you can stop playing chess or learning math if you strikingly stick to this method.
A better method is to timebox how much time you spend on solving a puzzle. The rule of thumb is that you should find the basic solution within five minutes.
For those five minutes, you will attempt to solve the problem all by yourself. You have to give it your all. If you solved it, good! Pat yourself in the back!
If you don't, you look at the answer.
If this cheating? No. Problem solving is about pattern recognition. If you couldn't find a solution, you couldn't find a pattern. That means you haven't learned that pattern.
By spending those earnest five minutes trying to solve the problem, you will understand the problem well. You will understand why your natural solution didn't work. When you look at the solution, it is meaningful. Your emotional reaction to seeing the solution will make it easier for you to remember it, creating that desire pattern for you to recognize the next time you see a similar problem.
I also learned this tactic by looking at the solution. I found this strategy in a chess book, which in turn adopted it from what seems to be a math teaching tactic in Russia.