c++ | prefix sum array | easy
```\nclass ProductOfNumbers {\npublic:\n    // vector \'v\' will store the prefix products\n    vectorv;\n    ProductOfNumbers() {\n        \n    }\n    \n    v
```\nclass ProductOfNumbers {\npublic:\n    // vector \'v\' will store the prefix products\n    vector<int>v;\n    ProductOfNumbers() {\n        \n    }\n    \n    void add(int num) {\n        // if num is 0 clear the vector\n        if(num==0) {\n            v.clear();\n            return;\n        }\n        \n        // otherwise push the prefix product\n        if(v.empty()) {\n            v.push_back(num);\n        }\n        else {\n            v.push_back(v.back()*num);\n        }\n    }\n    \n    int getProduct(int k) {\n        // if k is exceeding the size of the vector that means 0 must have appeared in the stream. 0 has appeared that\'s why vector got cleared and size became less than k.\n        // so product must be 0\n        if(k>v.size()) {\n            return 0;\n        }\n        \n        // otherwise find the product of the last k elements \n        if(k==v.size()) {\n            return v[k-1];\n        }\n        return v.back()/(v[v.size()-k-1]);\n    }\n};
[]