Java Solution Using ArrayList 86% Faster
\nclass ProductOfNumbers {\n    ArrayList<Integer> list;\n    int prev;\n    \n    public ProductOfNumbers() {\n        list = new ArrayList<>();\n        prev 
```\nclass ProductOfNumbers {\n    ArrayList<Integer> list;\n    int prev;\n    \n    public ProductOfNumbers() {\n        list = new ArrayList<>();\n        prev = 1;\n    }\n    \n    public void add(int num) {\n        if(num == 0){\n            list = new ArrayList<>();\n            prev = 1;\n        }\n        else{\n            prev = prev * num;\n            list.add(prev);\n        }\n    }\n    \n    public int getProduct(int k) {\n        int n = list.size();\n        if(k == n){\n            return list.get(n-1);\n        }\n        else if(k > n){\n            return 0;\n        }\n        else{\n            return list.get(n-1) / list.get(n-k-1);\n        }\n    }\n}\n```
['Array', 'Java']