Given an array of integers, return a new array such that each element at index i of the new array is the product of all the numbers in the original array except the one at i.
For example, if our input was [1, 2, 3, 4, 5], the expected output would be [120, 60, 40, 30, 24]. If our input was [3, 2, 1], the expected output would be [2, 3, 6].
Follow-up: what if you can’t use division?
As a Mental Exercise… here’s what I’d to do approach this:
I feel like I’m gonna need a Outer Loop that iterates through the array and just keeps the position. Then an inner loop will go through all the numbers except for the position held in the outer loop. The answer will be stored in a output array and returned when all the loops are done.
Looking forward to it’s implementation!
So the solution was pretty much what I thought it was, I needed an outer loop to pass through the array and hold the index positon, while the inner loop multiplies the remaining elements together. In my initial solution, I printed the output to the console, but I did NOT create a new array as the problem required. Therefore I have added my corrected code below and 2nd video.