✅✅Beats 100%🔥C++🔥Python|| 🚀🚀Super Simple and Efficient Solution🚀🚀||🔥Python🔥C++✅✅
Complexity
Time complexity: O(n)

Space complexity: O(1)
Code⬆️👇⬆️UPVOTE it⬆️👇⬆️
# Complexity
- Time complexity: $$O(n)$$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

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

# Code
```cpp []
class ProductOfNumbers {
 public:
  ProductOfNumbers() : prefix{1} {}
  void add(int num) {
    if (num == 0)
      prefix = {1};
    else
      prefix.push_back(prefix.back() * num);
  }
  int getProduct(int k) {
    return k >= prefix.size() ? 0 : prefix.back() / prefix[prefix.size() - k - 1];
  }

 private:
  vector<int> prefix;
};
```
```python []
class ProductOfNumbers:
  def __init__(self):
    self.prefix = [1]

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

  def getProduct(self, k: int) -> int:
    return 0 if k >= len(self.prefix) else self.prefix[-1] // self.prefix[len(self.prefix) - k - 1] 
```
⬆️👇⬆️UPVOTE it⬆️👇⬆️
['Array', 'Math', 'Design', 'Data Stream', 'Prefix Sum', 'C++', 'Python3']