Solution Review: Array of Products of All Elements
This review provides a detailed analysis of how to solve the "Array of Products of All Elements" challenge.
Solution #
Press + to interact
fn product_array(arr: &Vec<i32>) -> Vec<i32> {let mut sol: Vec<i32> = vec![0; arr.len()];let mut temp = 1;for x in 0..arr.len(){sol[x] = temp;temp = temp*arr[x];}temp = 1;for x in (0..arr.len()).rev(){sol[x] *= temp;temp *= arr[x];}return sol;}
Explanation
In this problem, you need to calculate the product of elements in a specific way. In the output array, the value at index i
will be equal to the product of all the elements of the given array arr
...
Access this course and 1400+ top-rated courses and projects.