Search for a command to run...
Try your own input
Change the array and replay the algorithm from step one.
Initialization
There are 6 windows of size 3. Re-scanning each one costs O(k), giving O(n·k) overall.
Brute Force
1function maxSlidingWindow(arr, k) {2 const n = arr.length;3 const ans = [];//n: 8k: 3ans: []4 for (let i = 0; i <= n - k; i++) {5 let maxi = arr[i];6 for (let j = i; j < i + k; j++) {7 maxi = Math.max(maxi, arr[j]);8 }9 ans.push(maxi);10 }11 return ans;12}