Probably a better solution
int * findProduct(int arr[], int size) { int * product = new int[size]; int p = 1, i; // Write your code here for( i=0; i < size; i++) p *= arr[i]; for(i=0; i< size; i++) product[i] = p/arr[i]; return product; }
Probably a better solution
int * findProduct(int arr[], int size) { int * product = new int[size]; int p = 1, i; // Write your code here for( i=0; i < size; i++) p *= arr[i]; for(i=0; i< size; i++) product[i] = p/arr[i]; return product; }
Hi Shubham ,
This is Maida from Educative.
In response to your feedback, thank you for reaching out to us with your suggestion. Yes, the algorithm you have suggested is correct, and it’s a very smart solution. In the course, we have suggested a very straightforward solution. But we really appreciate that you have taken the time to come up with a better version of it.
We hope Educative has inspired to further your learning.
Best Regards,
Maida | Developer Advocate
Educative Inc.