Challenge: Array of Products of All Elements Except Itself

Given an array, return an array where each index stores the product of all numbers except the number on the index itself. Implement your solution in Java and see if your output matches the expected output!

Problem Statement

In this problem, you have to implement the int[] findProduct(int[] arr) method which will modify arr in such a way that in the output, each index i will contain the product of all elements present in arr except the element stored on that index i.

Method Prototype

int[] findProduct(int[] arr)


An array of integers. This array can be of any (valid) size and elements can be repeated.


An array with products stored at each position.

Sample Input

arr = {1,2,3,4}

Sample Output

arr = {24,12,8,6}

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.