Swift | Prefix Sum
Complexity
Time complexity: O(1) for add, O(1) for getProduct, resulting in O(n) total TC in which n is the total number of calls to add and getProduct.

Space
# Complexity
- Time complexity: $$O(1)$$ for add, $$O(1)$$ for getProduct, resulting in $$O(n)$$ total TC in which $$n$$ is the total number of calls to add and getProduct.
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: $$O(n)$$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```swift []
class ProductOfNumbers {
    var prf = [1]
    
    func add(_ num: Int) {
        if num == 0 { prf = [1] }
        else { prf.append(prf.last! * num) }
    }
    
    func getProduct(_ k: Int) -> Int {
        if prf.count <= k { return 0 }
        return prf.last! / prf[prf.count - k - 1]
    }
}
```
['Swift', 'Prefix Sum']