Java || Prefix Product Array || beats 99.91% || 13ms || add - O(1) getProduct - O(1)
\n    List list;\n\n\t// O(1)\n\tpublic ProductOfNumbers() {\n\t\tlist = new ArrayList<>();\n\t\tlist.add(1);\n\t}\n\n\t// O(1)\n\tpublic void add(int num) {\n\
\n    List<Integer> list;\n\n\t// O(1)\n\tpublic ProductOfNumbers() {\n\t\tlist = new ArrayList<>();\n\t\tlist.add(1);\n\t}\n\n\t// O(1)\n\tpublic void add(int num) {\n\t\tif (num == 0) {\n\t\t\tlist = new ArrayList<>();\n\t\t\tlist.add(1);\n\t\t} else\n\t\t\tlist.add(list.get(list.size() - 1) * num);\n\t}\n\n\t// O(1)\n\tpublic int getProduct(int k) {\n\t\tint size = list.size();\n\t\tint start = size - k;\n\t\tif (start <= 0)\n\t\t\treturn 0;\n\t\treturn list.get(size - 1) / list.get(start - 1);\n\t}\n
[]