Product of Array Except Self

Write the code, see it run, pass the checks.

The problem

  • medium
  • Code

Write productExceptSelf(nums): return a new array where each position holds the product of every number in nums except the one at that position. Don't use division: nums may contain zeros. nums has at least two numbers; leave it unchanged. For example, productExceptSelf([1, 2, 3, 4]) is [24, 12, 8, 6]. The checks include 100,000 numbers, so multiplying everything again for each position is too slow.

Your code must pass

  • Multiplies all the other numbers, leaving nums unchanged
  • Handles a single zero
  • Handles more than one zero
  • Is fast enough for 100,000 numbers