Quick Overview

Implement exact factorial for nonnegative n up to 1,000, including the zero case. The result may exceed fixed-width integer ranges, and the implementation should not depend on deep recursion.

Compute an Exact Factorial

Company: Wayve

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

# Compute an Exact Factorial Implement `factorial(n)` and return the exact integer value of `n!`. `0!` is defined as `1`. The input is always a valid nonnegative integer; no input parsing or error handling is required. ## Constraints - `0 <= n <= 1,000` - The result may exceed fixed-width integer ranges, so it must remain exact. - Avoid recursion-depth dependence for the upper end of the range. ## Examples - `factorial(0) == 1` - `factorial(5) == 120` ## Candidate clarifications Confirm the required numeric representation, the definition of `0!`, and whether invalid or negative inputs need handling.

Quick Answer: Implement exact factorial for nonnegative n up to 1,000, including the zero case. The result may exceed fixed-width integer ranges, and the implementation should not depend on deep recursion.

Implement factorial(n). Return n! exactly as a decimal string so the result is portable across all supported languages. The input is a non-negative integer, 0! is 1, and the implementation must not depend on recursion depth.

Constraints

  • 0 <= n <= 1,000
  • Return the exact decimal representation of n!.
  • Do not rely on recursion depth.

Examples

Input: (0,)

Expected Output: '1'

Explanation: Checks the exact decimal factorial, including 0! and values beyond fixed-width ranges.

Input: (1,)

Expected Output: '1'

Explanation: Checks the exact decimal factorial, including 0! and values beyond fixed-width ranges.

Hints

  1. Start with 1 and multiply by each integer from 2 through n.
  2. Use a big-integer type or a decimal limb array where fixed-width multiplication would overflow.

Loading coding console...