Ad
  • Custom User Avatar

    I initially wrote a recursive function for this problem, and it worked for small numbers. However, the test cases included large numbers, which caused too many recursive calls, exceeding Python’s recursion depth limit and resulting in an error. To fix this, I switched to an iterative approach using a for loop, which avoids recursion limits and runs efficiently for large inputs.