Tell us what’s happening:
Could someone explain why this recursive function works correctly up to n=997 but has a maximum recursion limit beyond that? Does this mean we can’t solve this problem recursively or am I missing something obvious? Thanks!
Your code so far
def sum_of_squares(n):
if n == 1:
return 1;
result = n*n + sum_of_squares(n-1)
return result
print(sum_of_squares(997))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36
Challenge Information:
Daily Coding Challenge - Sum of Squares
https://www.freecodecamp.org/learn/daily-coding-challenge/2025-08-19