Exclude current element17.08
Except-self problems forbid using a[i] in the answer at i. Combine left and right. Division by a[i] is illegal if zeros exist or if the problem bans it.
answer[i] = left[i] combined with right[i]. Two passes, O(1) extra if you reuse the output array carefully.
Same skill, three traces. Read all three before you try it.
01sum except - given
a = [4, 1, 9]- walk
14-4=10,14-1=13,14-9=5- result
[10, 13, 5]
02with zero - given
a = [2, 0, 3]- walk
product except:
0,6,0- result
[0, 6, 0]— division would crash on0
03two zeros - given
a = [0, 1, 0]- walk
every except-product is
0- result
[0, 0, 0]
sumExcept(a) and productExcept(a).a is an array of integers.sumExcept[i] is the sum of every value except a[i]. productExcept[i] is the product of every value except a[i]. Do not divide.On
[4, 1, 9], sumExcept is [10, 13, 5]. On [2, 0, 3], productExcept is [0, 6, 0].constraintsa is a non-empty integer array.
- Product of Array Except Self0/3 skills ready · arrays · mediumopen
- Product of Array Except Self0/3 skills ready · arrays · mediumopen
Every Check with Awel is frozen here. Open one to read the code or load it back into the editor.