Very Simple to Understand Solution in Java/C++/Python (O(N))((100%)) ✅✅✅
Intuition
Very Similar to PrefixSum But we have to track position of last Zero .
we need to return (pre[n-1]/pre[n-k-1])

if last zero's index is in range of k
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
1. Very Similar to PrefixSum But we have to track position of last Zero .
2. we need to return (pre[n-1]/pre[n-k-1])
    - if last zero's index is in range of k from last(size of list) we return 0 
        - multiplying anything with zero gives zero 😢.

# Approach
<!-- Describe your approach to solving the problem. -->
1. Store the prefixProducts in List 
    - if current number is not zero we add (current * previous number)
    - if number is zero we clear list and then add 1 in list. ( clear list, since zero is comming the previous multiplications will no longer matter 🗿).

# Update on Optimization
1. since we are reseting the list when encountering a zero we can just check **k >= sizeof(list)** 
    - if true return 0
    - else return **(pre[n-1]/pre[n-k-1])** (n is size of list)
# Complexity
- Time complexity:O(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

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

# Code
```java []
class ProductOfNumbers {
    List<Integer> prefixProduct;
    public ProductOfNumbers() {
        prefixProduct = new ArrayList<>();
        prefixProduct.add(1);
    }
    public void add(int num) {
        if (num == 0) {
            prefixProduct.clear();
            prefixProduct.add(1);
        } else {
            prefixProduct.add(num * prefixProduct.get(prefixProduct.size() - 1));
        }
    }
    public int getProduct(int k) {
        int size = prefixProduct.size();
        if (size <= k) return 0;
        return prefixProduct.get(size - 1) / prefixProduct.get(size - k - 1);
    }
}

```
```Python3 []
class ProductOfNumbers:
    def __init__(self):
        self.prefix_product = [1]

    def add(self, num: int) -> None:
        if num == 0:
            self.prefix_product = [1]
        else:
            self.prefix_product.append(num * self.prefix_product[-1])

    def getProduct(self, k: int) -> int:
        size = len(self.prefix_product)
        if size <= k:
            return 0
        return self.prefix_product[-1] // self.prefix_product[size - k - 1]
```
```C++ []
class ProductOfNumbers {
public:
    vector<int> prefixProduct;
    ProductOfNumbers() {
        prefixProduct.push_back(1);
    }
    void add(int num) {
        if (num == 0) {
            prefixProduct.clear();
            prefixProduct.push_back(1);
        } else {
            prefixProduct.push_back(num * prefixProduct.back());
        }
    }
    int getProduct(int k) {
        int size = prefixProduct.size();
        if (k >= size) return 0;
        return prefixProduct.back() / prefixProduct[size - k - 1];
    }
};
```
['Prefix Sum', 'C++', 'Java', 'Python3']