C++, single vector
\nclass ProductOfNumbers {\npublic:\n    vector<int> prods;\n    \n    ProductOfNumbers() {\n        prods = {1};\n    }\n    \n    void add(int num) {\n       
```\nclass ProductOfNumbers {\npublic:\n    vector<int> prods;\n    \n    ProductOfNumbers() {\n        prods = {1};\n    }\n    \n    void add(int num) {\n        if (num == 0) {\n            prods.clear();\n            prods.push_back(1);\n        }\n        else {\n            prods.push_back(prods.back()*num);\n        }\n    }\n    \n    int getProduct(int k) {\n        if (k >= prods.size()) return 0;\n        \n        return prods.back()/(prods[prods.size()-1-k]);\n    }\n};\n```
[]