Notice Period

Everyone Else's Product

medium

For each position in a list of integers, compute the product of every other element.

Return a list out where out[i] is the product of all nums[j] for j != i.

House rules: no division, and the whole thing in O(n) time.

Example 1
in nums = [1, 2, 3, 4]
out [24, 12, 8, 6]
Example 2
in nums = [-1, 1, 0, -3, 3]
out [0, 0, 9, 0, 0]
Constraints
  • · 2 <= len(nums) <= 10^5
  • · -30 <= nums[i] <= 30
  • · answers fit in a 64-bit integer
similar problem on LeetCode ↗
solution.pyloading python…
test results
Hit ▶ Run to test your code against the visible cases.