RecursionError in Python submissions on LeetCode judge
0 reputation · 24 Oct 2025, 17:49 UTC
Recursive Python solutions are common on LeetCode, and local development environments often allow increasing the recursion limit.
The judge environment is documented to use a default recursion limit and to restrict attempts to raise it. The precise interaction between sys.setrecursionlimit and the judge's runtime is not clearly specified in the public language documentation, and the effective maximum depth that can be relied upon for portable submissions is uncertain.
For solutions that must remain portable across local testing and the online judge, the acceptable recursion depth assumption needs clarification.
What is the effective recursion limit enforced for Python submissions on the LeetCode judge? Is sys.setrecursionlimit permitted to change the limit, or is it ignored? What depth should be considered safe for recursive implementations that must pass on the judge?