Array of Array Products
public int[] solve(int[] arr) {
int [] out = new int[arr.length];
int product =1;
for(int i=0;i<arr.length;i++){
out[i]=product;
product = product*arr[i];
}
product=1;
for(int j=arr.length-1;j>=0;j--){
out[j] = out[j]*product;
product = product* arr[j];
}
return out;
}
n is size of an array
Time complexity is O(n)
Space complexity is O(n)
Top comments (0)