[JS] Three solutions
Solution 1:\n\n\nclass ProductOfNumbers {\n    constructor() {\n        this.stream = new Array(); \n    }\n    add(num) {  // O(1)\n        this.stream.push(nu
**Solution 1:**\n\n```\nclass ProductOfNumbers {\n    constructor() {\n        this.stream = new Array(); \n    }\n    add(num) {  // O(1)\n        this.stream.push(num);\n    }\n    getProduct(k) { // O(k) [0 <= k <= n]\n        let i = this.stream.length - k,\n            product = 1;\n        while(i < this.stream.length) {\n            product *= this.stream[i];\n            ++i;\n        }\n        return product;\n    }\n}\n```\n\n---\n\n**Solution 2:**\n\n```\nclass ProductOfNumbers {\n    constructor() {\n        this.stream = new Array(); \n    }\n    add(num) {  // O(n)\n        for(let i = this.stream.length - 1; i >= 0; --i) {\n            this.stream[i] *= num;\n        }\n        this.stream.push(num);\n    }\n    getProduct(k) { // O(1)\n        return this.stream[this.stream.length - k];\n    }\n}\n```\n\n---\n\n**Solution 3:**\n\n```\nclass ProductOfNumbers {\n    constructor() {\n        this.stream = [1];\n    }\n    add(num) {    // O(1)\n        if(!num) {  // if num is 0, product of all nums before will consider 0 and becomes 0\n            this.stream = [1];\n        } else {\n            const currProd = this.stream[this.stream.length - 1] * num;\n            this.stream.push(currProd);\n        }\n    }\n    getProduct(k) {    // O(1)\n        const size = this.stream.length;\n        if(k >= size) {\n            return 0;\n        }\n        // divide the last product with product at kth distance from last => will give the product of last k nums\n        return this.stream[size - 1] / this.stream[size - k - 1];\n    }\n}\n```
['Prefix Sum', 'JavaScript']