Fix the window length in advance04.01
k is given. Every window has length k. You do not discover length. You slide a block of k cells.
Length is always k = R-L+1. For n cells there are n-k+1 windows.
Same skill, three traces. Read all three before you try it.
01k=2 on four - given
a = [1, 2, 3, 4],k=2- walk
windows
[0,1],[1,2],[2,3]each has length
2count = 4-2+1=3- result
3windows
02k=2 on three - given
a = [4, 1, 9],k=2- walk
[0,1]then[1,2]count = 2- result
2windows
03k bigger than n - given
a = [7],k=2- walk
n=1<2no block of
2cells- result
0windows
windowCount(n, k).n is the array length. k is the fixed window length. Each window includes k cells, R-L+1 = k. Count is max(0, n-k+1).Return the count.
On
[1, 2, 3, 4] k=2 → 3. On [4, 1, 9] k=2 → 2. On [7] k=2 → 0.constraintsa is nonempty. k ≥ 1. When k > n the window count is 0.
- 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.