[Python] Prefix product using extra array. Clean code with comments.
The idea is similar to all prefix sum problems except we need to handle the 0 value. When we meet a 0, reset the product array.\n\nclass ProductOfNumbers(object
The idea is similar to all prefix sum problems except we need to handle the `0` value. When we meet a `0`, reset the product array.\n```\nclass ProductOfNumbers(object):\n\n    def __init__(self):\n        # init prefix 1\n        self.nums = [1]\n\n    def add(self, num):\n        """\n        :type num: int\n        :rtype: None\n        """\n        # when we meet zero, reset the nums\n        if num == 0:\n            self.nums = [1]\n        else:\n            # otherwise append the new prefix product\n            self.nums.append(self.nums[-1] * num)\n\n    def getProduct(self, k):\n        """\n        :type k: int\n        :rtype: int\n        """\n        # required k is larger than the length of nums minus one (since we have a fake 1 prefix)\n        if k > len(self.nums) - 1:\n            return 0\n        # using division to get the product\n        return self.nums[-1] / self.nums[-k - 1]\n\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```
[]