I have uploaded my code in leetcode for this same problem and it is submitted there successfully but here I cannot pass two test cases out of 3.
I cannot pass two test cases out of 3
#include <bits/stdc++.h> using namespace std; int main() { int n;cin>>n; vector a(n); for(int i = 0;i<n;i++){ cin>>a[i]; } vector ans(n); ans[0] =1; for(int i = 1;i<n;i++){ ans[i] = ans[i-1] * a[i-1]; } int r = 1; for(int i = n-1;i>=0;i–){ ans[i] *= r; r *= a[i]; } for(auto i:ans) cout<<i<<" "; return 0; }