Beats 100% on runtime [EXPLAINED]
IntuitionEfficiently retrieve the product of the last k numbers from a growing stream. Keeping all numbers would make querying slow, so instead, I store cumulat
# Intuition
Efficiently retrieve the product of the last k numbers from a growing stream. Keeping all numbers would make querying slow, so instead, I store cumulative products in a way that allows quick division-based lookups while handling zeros properly.

# Approach
Maintain a list of prefix products where each entry stores the product of all numbers so far, resetting when encountering zero so when querying, I divide the last stored product by the product k steps back to get the answer in constant time.

# Complexity
- Time complexity:
Both add and getProduct run in O(1) since inserting into a vector and accessing elements are fast.

- Space complexity:
O(n) because I store cumulative products in a vector, growing with the number of elements added.

# Code
```rust []
struct ProductOfNumbers {
    prefix: Vec<i32>,
}

impl ProductOfNumbers {
    fn new() -> Self {
        Self { prefix: vec![1] } // Start with a dummy 1 to simplify calculations
    }

    fn add(&mut self, num: i32) {
        if num == 0 {
            self.prefix = vec![1]; // Reset on zero
        } else {
            let last = *self.prefix.last().unwrap();
            self.prefix.push(last * num);
        }
    }

    fn get_product(&self, k: i32) -> i32 {
        let k = k as usize; // Convert i32 to usize safely
        let n = self.prefix.len();
        if k >= n {
            return 0; // If k exceeds valid range (due to reset), return 0
        }
        self.prefix[n - 1] / self.prefix[n - 1 - k]
    }
}

```
['Array', 'Math', 'Binary Search', 'Dynamic Programming', 'Design', 'Binary Indexed Tree', 'Data Stream', 'Hash Function', 'Prefix Sum', 'Rust']