FastPrepFactorial Without Multiplication

Factorial Without Multiplication

Wayve logoWayve● EasyFULLTIMEPHONE SCREEN
Learn

Problem statement

Return n! without using the multiplication operator. Implement multiplication through repeated addition. Return -1 when n is outside the supported range 0..12.

Function

factorialWithoutMultiplication(n: int) → int

Examples

Example 1

n = 5return = 120

Repeated addition builds 1 × 2 × 3 × 4 × 5 = 120 without using the multiplication operator.

Example 2

n = 0return = 1

By definition, zero factorial is one.

Constraints

  • -100 <= n <= 100
  • Do not use multiplication in the submitted function.

More Wayve problems

See Wayve hiring insights
public int factorialWithoutMultiplication(int n) {
  // Write your code here.
}
n5
expected120
Checking account…