c++ solution using map | comments for better understanding ✔
\nclass ProductOfNumbers {\npublic:\n    unordered_map<int,int> map; // {index, prefix product}\n    vector<int> zeros;  // index of zeros in stream\n    int i=
```\nclass ProductOfNumbers {\npublic:\n    unordered_map<int,int> map; // {index, prefix product}\n    vector<int> zeros;  // index of zeros in stream\n    int i=0;\n    \n    ProductOfNumbers() {\n        \n    }\n    \n    void add(int num) {\n        if(num==0){\n            map[i]= 1;\n            zeros.push_back(i);\n        }\n        else map[i]= ((map.find(i-1) == map.end())? num : map[i-1]*num);\n        \n        i++;\n    }\n    \n    int getProduct(int k) {\n        int l= i-k;\n        int ind= lower_bound(zeros.begin(),zeros.end(),l)-zeros.begin();\n        if(ind!= zeros.size()) return 0;\n        \n        return ((i-k-1)>=0)? map[i-1]/map[i-k-1] :map[i-1];\n    }\n};\n\n/**\n * Your ProductOfNumbers object will be instantiated and called as such:\n * ProductOfNumbers* obj = new ProductOfNumbers();\n * obj->add(num);\n * int param_2 = obj->getProduct(k);\n */\n```
['C', 'C++']