diff --git a/GFG/product_array.cpp b/GFG/product_array.cpp new file mode 100644 index 0000000..d2b1f9c --- /dev/null +++ b/GFG/product_array.cpp @@ -0,0 +1,74 @@ +// Question link is - https://practice.geeksforgeeks.org/problems/product-array-puzzle4525/1 + + +//Initial template for C++ + +#include +using namespace std; + + + + // } Driver Code Ends +//User function template for C++ + +class Solution{ + public: + // nums: given vector + // return the Product vector P that hold product except self at each index + vector productExceptSelf(vector& nums, int n) { + long long int pro=1,zero=0; + for(int i=0;i1) + pro=zero; + vector ans; + for(int i=0;i0) + { + if(nums[i]==0 && zero==1) + ans.push_back(pro); + else + ans.push_back(0); + } + else + { + long long int x=pro/nums[i]; + ans.push_back(x); + } + } + return ans; + } +}; + + +// { Driver Code Starts. +int main() + { + int t; // number of test cases + cin>>t; + while(t--) + { + int n; // size of the array + cin>>n; + vector arr(n),vec(n); + + for(int i=0;i>arr[i]; + } + Solution obj; + vec = obj.productExceptSelf(arr,n); // function call + + for(int i=0;i