Replace each element of the array with product of every other element

Given an array of integers, replace each element of the array with the product of every other element in the array. Return the modified array.

Example Solution

Let array arr equal to [ 1, 2, 3, 4, 5 ]. If we multiply the elements accordingly, we'll get the array [ 120, 60, 40, 30, 24 ]. The solution should return this array.

Contributed by Murat Sütunç