# Is it normal to spend 4+ hours on a simple recursion problem?

I’m trying to write a program to recursively find the greatest element in a list. I’ve tried to come up with a solution for over 4 hours and nothing seems to work. I don’t actually want the solution because I’m sure there will be tons of YouTube videos and articles explaining it. My question is:

Is this normal? Try to be honest.
I’m tired of spending hours on simple problems and not even getting a solution. Am I stupid or do I just need more practice with recursion(I’ve done 7+ recursion problems)

Thanks!!

Recursion is hard. Taking a while to reach a solution while you are still learning is normal. I would perhaps suggest a different strategy than just trying alone for 4 hours though - asking for help once you know where you are getting stuck is a great idea.

1 Like

For someone learning recursion? Absolutely.

As Jeremy says, recursion is hard. It melts your brain when you are learning it. If you solved it and got something out of it, then I call that a success.

And I think recursion is over emphasized. Yes, it’s important to learn, but it took me at least a year before I finally understood it. In the real world, it’s really only used in a specific set of problems, many of which don’t commonly show up in web dev. In 3.5 years as a professional dev, I’ve only used it once - and that wasn’t part of the production app. I know a lot of professional devs that are not comfortable with it. It is important to learn because it makes you think about programming in a different way and it shows up on interviews sometimes.

But cut yourself some slack. I’d think of it as more of a longterm project - don’t expect to nail it this week.

Like Jeremy says, reach out. And watch videos and read posts.

2 Likes

I would do that if I was completely clueless, but I was really close to the solution. Like, the function would get the top 2 greatest elements in the list but stop there for some reason. Then after trying for 3 more hours I got the solution, completely on my own. I feel so proud even though I know it’s a pretty easy problem lol.

Thanks a lot for your help!

Great! I’m not stupid

Completely agree, it’s very hard. The basic…thing or concept isn’t hard: Recursion is a when a function calls itself.
It’s easy to do a recursion problem when it lends itself to it, like printing the Fibonacci sequence or factorials. It’s hard to do stuff that can are usually done recursively, iteratively. And it’s also hard to do things that are normally done iteratively, recursively. At least for me.

That’s the only reason I’m learning it lol.

Ok

Ok

And, thanks a lot for your help! I feel a lot better about myself now.

Here’s my solution:

``````def maxRec(array, maxElemInd=0):
print(array)
if len(array) == 0:
return 0
elif len(array) == 1:
return array[0]
elif maxElemInd+1 == len(array):
return array[maxElemInd]

elif maxElemInd+1 < len(array):
print(f"In --> {maxElemInd}: {array}")

if array[maxElemInd] > array[maxElemInd+1]:
array.pop(maxElemInd+1)
return maxRec(array, maxElemInd)

elif array[maxElemInd+1] > array[maxElemInd]:
array.pop(maxElemInd)

return maxRec(array, maxElemInd)

``````