Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
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.