Slide by dropping left and adding right04.03
After the first window [0,k), each step i from k to n-1 does: drop a[i-k], add a[i]. L and R both increase by 1. Length stays k.
One exclude and one include per i. Do not rescan the k cells. Stop when i would equal n. If n == k there is only the seed window.
Same skill, three traces. Read all three before you try it.
01two slides - given
a = [1, 2, 3, 4],k=2- walk
seed
[1,2]i=2dropa[0]=1adda[2]=3→[2,3]i=3dropa[1]=2adda[3]=4→[3,4]- result
- windows
[1,2],[2,3],[3,4]
02one slide - given
a = [4, 1, 9],k=2- walk
seed
[4,1]i=2drop4add9→[1,9]- result
- windows
[4,1],[1,9]
03no slide - given
a = [4, 1],k=2- walk
seed
[4,1]iwould start at2=n, stop- result
- only
[4, 1]
slideK(a, k).a is an array of integers. k is the fixed length. Each slide drops a[i-k] and adds a[i]. The window always includes k cells.Print each window. Return nothing.
On
[1, 2, 3, 4] k=2; [4, 1, 9] k=2; [4, 1] k=2.constraintsa is nonempty. 1 ≤ k ≤ n.
- Maximum Average Subarray I0/3 skills ready · sliding window · easyopen
- Maximum Average Subarray I0/3 skills ready · sliding window · easyopen
Every Check with Awel is frozen here. Open one to read the code or load it back into the editor.