In this post, we are going to discuss leetcode 1352 — Product of the Last K Numbers, which is recently asked in Google, Uber, and Amazon interviews.
Problem Analysis
Design an algorithm that accepts a stream of integers and retrieves the product of the last
k
integers of the stream.Implement the
ProductOfNumbers
class:
1.ProductOfNumbers()
Initializes the object with an empty stream.
2.void add(int num)
Appends the integernum
to the stream.
3.int getProduct(int k)
…