prefix_products
with a single element [1]
to handle the neutral element of multiplication.add
is called with a number num
:
num
is not zero, multiply num
with the last element in prefix_products
and append the result to prefix_products
.num
is zero, reset prefix_products
to [1]
.getProduct
is called with an integer k
:
k
is larger than the current size of prefix_products
, return 0.prefix_products
by the element at the position size - k - 1
.