#8 most askedVery commonMediumPrefix sum
Product of Array Except Self
New to Prefix sum? Learn it from scratch firstPrefix Sums โ
๐ข Asked in real interviews
No reports yet. Were you asked this? Be the first to say where.Return a list where answer[i] is the product of every number in nums except nums[i]. Do it in O(n) without division.
[1, 2, 3, 4] โ [24, 12, 8, 6]
๐งช Practice
Write your solution, then press Run tests. Explain your approach out loud as you go.
def product_except_self(nums):
pass
Output appears here. Press Run or Ctrl/โ + Enter.
Try it first. Struggling for a few minutes is how it sticks.