Efficient O(1) solution in Python
See a couple solutions recording the last index of 0, in fact, we don\'t need that, we can just reset the stack after reaching a 0 because we don\'t care what i
See a couple solutions recording the last index of 0, in fact, we don\'t need that, we can just reset the stack after reaching a 0 because we don\'t care what input is before that.\n\n```\nclass ProductOfNumbers:\n    def __init__(self):\n        self.arr = [1]\n\n    def add(self, num: int) -> None:\n        if (num == 0):\n            self.arr = [1] # reset, anything k reaches before will lead 0\n            return\n    \n        self.arr.append(self.arr[-1] * num)\n\n    def getProduct(self, k: int) -> int:\n        # [3, 0] k = 1, len = 1 return 0\n        if (k >= len(self.arr)):\n            return 0\n    \n        return self.arr[-1] // self.arr[-k-1]\n```
[]