BugForge
DSA

Demand Multiplier Except Self

Mediumprefix product 00:00

For each warehouse i, compute the product of all other warehouses' multipliers. You may not use division (multipliers can be 0).

Signature

productExceptSelf(nums: int[]) → int[]
Example 1
nums = [1,2,3,4]
output = [24,12,8,6]
[2·3·4, 1·3·4, 1·2·4, 1·2·3]
Example 2
nums = [-1,1,0,-3,3]
output = [0,0,9,0,0]

Constraints

  • 2 ≤ n ≤ 10^5
  • -30 ≤ nums[i] ≤ 30
  • every answer fits in a 32-bit int
Run checks the examples. Submit runs every hidden test (17, including large inputs that catch slow solutions).