ntree.ai

Product of Array Except Self

mediumArraysPrefix sum

Given an array of integers nums, return an array answer where answer[i] is the product of every element of nums except nums[i].

Example 1:

Input:  nums = [1, 2, 3, 4]
Output: [24, 12, 8, 6]
Explanation: 2*3*4, 1*3*4, 1*2*4, 1*2*3.

Constraints:

  • 2 <= len(nums) <= 10^5
  • -30 <= nums[i] <= 30
  • every prefix and suffix product fits in a 32-bit integer