Faster than 100%, simple logic.
The Logic is simple, you need to minimize the number of useless calculations. Since the size of the Test case is too large.\nUsing Dynamic programming, multiply
The Logic is simple, you need to minimize the number of useless calculations. Since the size of the Test case is too large.\nUsing Dynamic programming, multiply and store the product upto the position in the stack/array.\nIf you have a \'0\' in input... reset the array since product upto that would be zero.\n```\nclass ProductOfNumbers:\n\n    def __init__(self):\n        self.stack = deque()\n\n    def add(self, num: int) -> None:\n        if num==0 :\n            self.stack = []\n        else:\n            if not self.stack :\n                self.stack.append(num)\n            else:\n                self.stack.append(num*self.stack[-1])\n\n    def getProduct(self, k: int) -> int:\n        if k > len(self.stack) : return 0\n        if k==len(self.stack) : return self.stack[-1]\n        else: return (self.stack[-1]//self.stack[-(1+k)])\n\n\n# Your ProductOfNumbers object will be instantiated and called as such:\n# obj = ProductOfNumbers()\n# obj.add(num)\n# param_2 = obj.getProduct(k)\n```
['Dynamic Programming']