Bug Report for https://neetcode.io/problems/products-of-array-discluding-self
Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.
In Solutions - 3. Prefix & Suffix
Prefix and suffix are initialized like this -
pref = [0] * n
suff = [0] * n
and in loop it is written as
for i in range(1, n):
pref[i] = nums[i - 1] * pref[i - 1]
for i in range(n - 2, -1, -1):
suff[i] = nums[i + 1] * suff[i + 1]
Which makes pref[i] as 0 always as we have initiated it as 0 and not defined pref[0] anywhere so it makes the entire output array consisting of 0.
We need to initialize pref and suff as
pref = [1] * n
suff = [1] * n
Bug Report for https://neetcode.io/problems/products-of-array-discluding-self
Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.
In Solutions - 3. Prefix & Suffix
Prefix and suffix are initialized like this -
pref = [0] * n
suff = [0] * n
and in loop it is written as
for i in range(1, n):
pref[i] = nums[i - 1] * pref[i - 1]
for i in range(n - 2, -1, -1):
suff[i] = nums[i + 1] * suff[i + 1]
Which makes pref[i] as 0 always as we have initiated it as 0 and not defined pref[0] anywhere so it makes the entire output array consisting of 0.
We need to initialize pref and suff as
pref = [1] * n
suff = [1] * n