Simple JAVA Solution || BEATS 91.34% 
IntuitionMaintaining a list for calculating the product of the last k numbers. Instead of storing all numbers , we use prefix products to speed up product retri
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Maintaining a list for calculating the product of the last k numbers. Instead of storing all numbers , we use prefix products to speed up product retrieval.
# Approach
<!-- Describe your approach to solving the problem. -->
Product of last k numbers= prefixProduct[n]/prefixProduct[n-k]

T​his avoids iterating over k elements every time, reducing query time to O(1).
# Complexity
- Time complexity: O(1) -- for both add() and getProduct() method 
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(n) (List)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class ProductOfNumbers {
    List<Integer> l;
    public ProductOfNumbers() {
        l = new ArrayList<>();
        l.add(1);
    }
    public void add(int num) {
        if (num == 0) {
            l = new ArrayList<>();
            l.add(1);
        } 
        else l.add(num * l.get(l.size() - 1));
    }
    public int getProduct(int k) {
        if (l.size() - 1 < k) return 0;
        else return l.get(l.size() - 1) / l.get(l.size() - 1 - k);
    }
}
```
NOTE: If we encounter 0, we reset the list because multiplying anything by zero results in zero.
['Array', 'Math', 'Prefix Sum', 'Java']