Back to problems

Implement factorial and count trailing zeros

Algorithm · Upstart · Medium

1) Implement factorial Iterative approach Time complexity: $$O(n)$$ Space complexity: $$O(1)$$ Recursive approach Time complexity: $$O(n)$$ Space complexity: $$O(n)$$ due to recursion stack Discussion The iterative version avoids Python's recursion depth limit. Recursive factorial for n = 2000 exceeds Python's default recursion limit of approximately 1000, so you would need to call: before using the recursive version. Python integers have arbitrary precision, so computing…

Checking your access…