I am using python and I have correctly figured out the solution. But the problem is there is recursion depth limit in python which is only around 1000. So my code is not working for inputs greater than 1000
In Python there is limit of recursive calls. It can be set manually through cmd.
Check this out
Yes, python has a recursive limit to guard against the stack overflow. For this question, got for iterative approach…