DEV Community

Lautaro Suarez
Lautaro Suarez

Posted on

Product of Array Except Self

Third day posting about Blind 75 LeetCode Questions.

Today i will be solving the Product of Array Except Self.

Let`s set up the problem first.

We are being asked to return an array "answer" such that "answer[i]" is equal to the product of all the elements of "nums" except "nums[i]".

We will start by defining "resultArray" and "product"

Image description

Then we will make a first for loop and inside it we will re declared "product".

Image description

Inside of it for loop we will make a second loop and an if statement inside it that will check if "i" is not equal to "j" and if it is not it will re declared product multipliying it by "nums[j]".

Image description

And finally just inside the first loop we will push "product" into the first empty array declared.
Final code:

Image description

Thanks, i will be uploading every day.
Hope someone found it useful.

Lautaro.

Top comments (0)