Easy Solution based on Prefix Sum
IntuitionFirst try to solve in bruteforce approach
Then youll note preffix product pattern!ApproachComplexity
Time complexity:O(1)

Space complexity:O(N)
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

First try to solve in bruteforce approach
Then youll note preffix product pattern!

# Approach
<!-- Describe your approach to solving the problem. -->


# Complexity
- Time complexity:O(1)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

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

# Code
```cpp []
class ProductOfNumbers {
private:
    vector<int> ans;  // Stores prefix product

public:
    ProductOfNumbers() {
        ans.push_back(1);  
    }
    
    void add(int num) {
        if (num == 0) {
            ans.clear();
            ans.push_back(1); 
        } else {
            ans.push_back(ans.back() * num);
        }
    }
    
    int getProduct(int k) {
        if (k >= ans.size()) return 0;
        return ans.back() / ans[ans.size() - k - 1];
    }
};

```
['C++']