using prefix multiplication and
\nclass ProductOfNumbers {\n    List<Integer> prefix;\n    public ProductOfNumbers() {\n        prefix = new ArrayList<>();\n        prefix.add(1);\n    }\n    
```\nclass ProductOfNumbers {\n    List<Integer> prefix;\n    public ProductOfNumbers() {\n        prefix = new ArrayList<>();\n        prefix.add(1);\n    }\n    \n    public void add(int num) {\n        if(num==0){\n            prefix.clear();\n            prefix.add(1);\n        }\n        else prefix.add(num*prefix.get(prefix.size()-1));\n    }\n    public int getProduct(int k) {\n        if(k>=prefix.size()) return 0;\n        return prefix.get(prefix.size()-1)/prefix.get(prefix.size()-k-1);\n    }\n}\n```
['Prefix Sum', 'Java']