Medium · Arrays & hashing

Product of Array Except Self

You are given a list of integers, nums. Return a new list of the same length where each position holds the product of all the other numbers, leaving out the one at that position.

  • Do not use division.
  • Aim for O(n): a pass or two over the list, not a loop inside a loop.
  • The list can contain zeros and negative numbers.
nums = [1, 2, 3, 4]

→ [24, 12, 8, 6]   (24 = 2 × 3 × 4)
Record your take

No one has solved it yet.