Product of Array Except Self - aloalgo

Product of Array Except Self

Medium

You are given an integer array nums.

Your task is to compute an array answer where each answer[i] represents the product of all elements in nums excluding nums[i].

Return the array answer.

Example 1

Input
[1, 2, 3]
Output
[6, 3, 2]
Explanation:

For nums[0]=1, the product of elements except self is 23 = 6. For nums[1]=2, the product of elements except self is 13 = 3. For nums[2]=3, the product of elements except self is 1*2 = 2.

Example 2

Input
[0, 1, 2]
Output
[2, 0, 0]
Explanation:

For nums[0]=0, the product of elements except self is 12 = 2. For nums[1]=1, the product of elements except self is 02 = 0. For nums[2]=2, the product of elements except self is 0*1 = 0.

Loading...
Input
[1, 2, 3]
Output
[6, 3, 2]

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!