Write a recursive function in Python for a specific task
Write a recursive function in Python that performs the following task: [TASK_DESCRIPTION]. Ensure the function handles base cases and recursive cases correctly. Optimize the function to avoid stack overflow.
Use this when you need to implement a recursive solution for a problem in Python.