Katkat

Implement factorial and count trailing zeros

UpstartData Scientist · Onsite

Last updated

This question evaluates understanding of factorial computation and algorithmic techniques, including iterative versus recursive approaches, handling large integers and recursion constraints, and efficient counting of trailing zeros via number-theoretic reasoning.

Answer the following coding questions in Python.

1) Implement factorial

Implement a function factorial(n) that returns (n!) for a non-negative integer n.

  • Describe at least two different implementation approaches (e.g., iterative, recursive), and discuss constraints (e.g., recursion depth, large integers).

2) Count trailing zeros of a factorial

Given an integer n, compute the number of trailing zeros in the decimal representation of (n!) (i.e., how many zeros at the end).

  • Your solution should be efficient for large n (do not compute (n!) explicitly).
  • Specify time complexity.