C++ Time and Space Optimal | Simple & Easy
\nclass ProductOfNumbers {\npublic:\n    vector<int> arr; \n    ProductOfNumbers() {\n        arr = {1};\n    }\n    \n    void add(int num) {\n        // Check
```\nclass ProductOfNumbers {\npublic:\n    vector<int> arr; \n    ProductOfNumbers() {\n        arr = {1};\n    }\n    \n    void add(int num) {\n        // Checking if the number is not zero\n        if(num)\n            arr.push_back(arr.back() * num);\n        else\n            arr = {1};\n    }\n    \n    int getProduct(int k) {\n        int n = arr.size();\n        return (n - k - 1 >= 0) ? (arr.back() / arr[n - k - 1]) : 0;\n    }\n};\n```
['C']