FastPrepFactorial
Problems/Factorial

Factorial

AMD logoAMD● EasyINTERNONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report requests recursive factorial. The iterative comparison, 0 through 12 bound, zero case and callable interface are authored for practice; approximate source match 95%.

Return n!, the product of all integers from 1 through n. By definition, 0! = 1.

First implement the recursive recurrence, then compare it with an iterative implementation that uses constant extra space. The judge checks the returned value.

Function

factorial(n: int) → int

Examples

Example 1

n = 5return = 120

The product 1 × 2 × 3 × 4 × 5 is 120.

Example 2

n = 0return = 1

The empty product is defined as 1.

Constraints

  • 0 <= n <= 12.

More AMD problems

  • Insert After a Linked-List NodeONSITE INTERVIEW · Seen Oct 2026
  • LRU CacheONSITE INTERVIEW · Seen Oct 2026
  • Lowest Common Ancestor of a Binary TreePHONE SCREEN · Seen Oct 2026
All AMD interview questionsSee AMD hiring insights
Saved
public int factorial(int n) {
    // Write your code here.
}
Checking account…