Java🍵|Prefix sum✅|Easy Approach🔥
Complexity
Code
# Complexity
![image.png](https://assets.leetcode.com/users/images/db654747-2890-419c-88b6-0559b211f95d_1739577459.76397.png)
![image.png](https://assets.leetcode.com/users/images/5c239b31-ce27-45e5-9f70-f2921b76d557_1739577465.6280222.png)


# Code
```java []
class ProductOfNumbers {
    ArrayList<Integer> al = new ArrayList<>();
    int size = 0;

    public ProductOfNumbers() {
        al.add(1);
        size = 0;
    }

    public void add(int num) {
        if (num == 0) {
            al = new ArrayList<Integer>();
            al.add(1);
            size = 0;
        } else {
            al.add(al.get(size) * num);
            size++;
        }
    }

    public int getProduct(int k) {
        if (k > size)
            return 0;
        return (al.get(size) / al.get(size - k));
    }
}

/**
 * Your ProductOfNumbers object will be instantiated and called as such:
 * ProductOfNumbers obj = new ProductOfNumbers();
 * obj.add(num);
 * int param_2 = obj.getProduct(k);
 */
```
['Java']