Easy and Simple Solution
Please Like ❤️IntuitionWe need to efficiently retrieve the product of the last k numbers that were added. A naive approach is to iterate back k steps and comput
```java
class ProductOfNumbers {
    ArrayList<Integer> res;
    public ProductOfNumbers() {
        res = new ArrayList<>();
    }
    
    public void add(int num) {
        res.add(num);
    }
    
    public int getProduct(int k) {
        int i = res.size()-1;
        int product = 1;
        while(k-->0){
            product*=res.get(i);
            i--;
        }
        return product;
    }
}
```

# Please Like ❤️  
![Please Like](https://media.tenor.com/heEyHbV8iaUAAAAM/puss-in-boots-shrek.gif)  

# Intuition  
We need to efficiently retrieve the product of the last `k` numbers that were added. A naive approach is to iterate back `k` steps and compute the product. However, this can be optimized.

# Approach  
1. Use an `ArrayList<Integer>` (`res`) to store all added numbers.  
2. When `add(num)` is called, append `num` to `res`.  
3. When `getProduct(k)` is called, compute the product by iterating back `k` elements from the end.  
4. Return the computed product.

# Complexity  
- **Time Complexity:**  
  - `add(num)`: $$O(1)$$ – Appending to an `ArrayList` is constant time.  
  - `getProduct(k)`: $$O(k)$$ – We iterate back `k` elements to compute the product.  
- **Space Complexity:** $$O(n)$$ – We store all numbers in the `ArrayList`.
['Java']