Code example for Queue

Methods: add, remove, size

0
        this.period = period;
    } 
 
    public void newNum(long num) {
        sum += num;
        window.add(num);
        if (window.size() > period) {
            sum -= window.remove();
        } 
    } 
 
    public long getAvg() { 
        if (window.isEmpty()) return 0; // technically the average is undefined
        return sum / window.size();
    } 
 
}