Combine prefix and suffix17.05
At index i, prefix can describe a[0..i-1] and suffix a[i+1..n-1]. Together they describe everything except a[i].
Classic: product except self = prefixProd[i] * suffixProd[i+1]. Or min except self = min(preMin[i], sufMin[i+1]).
Same skill, three traces. Read all three before you try it.
01product except self - given
a = [2, 3, 4]- walk
except
2:3*4=12except
3:2*4=8except
4:2*3=6- result
[12, 8, 6]
02sum except self - given
a = [4, 1, 9]- walk
total
14, minusa[i]- result
[10, 13, 5]
03ends - given
a = [2, 3, 4],i = 0has empty prefix- walk
prefix identity
0for +,1for *- result
- only the suffix remains
productExceptSelf(a).a is an array of integers.Return an array where index
i is the product of every value except a[i]. Use prefix and suffix products. Do not divide.[2, 3, 4] → [12, 8, 6]. [1, 2, 3, 4] → [24, 12, 8, 6].constraintsa has length ≥ 2. values are integers.
- 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.