Fix a window width k. Each shift drops one element on the left and adds one on the right — the sum updates in O(1) if you track what left and what entered.