Factorial

math

Factorial

Google Python Interview Question

Google's data science team counts how many different orders a set of search results could be shown in. For n results, that count is the factorial of n: 1 × 2 × ... × n.

Write a function factorial(n) that returns the factorial of a whole number n from 0 to 18. The factorial of 0 is 1.

Asked of

  • Data Analyst
  • Data Engineer
  • Data Scientist
  • ML Engineer
  • AI Engineer

Example 1

Input

n = 5

Output

120

Example 2

Input

n = 0

Output

1

Explanation

In the first example, 5 results can be arranged in 1 × 2 × 3 × 4 × 5 = 120 orders. In the second example, there is exactly one way to arrange no results, so the factorial of 0 is 1.

Submit also runs 3 hidden test cases that check edge cases.