DEV Community

Lautaro Suarez
Lautaro Suarez

Posted on

1

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.

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay