Skip to content

Bug Report for solution of products-of-array-discluding-self #5932

Description

@Pranav4op

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions