Sliding Window Maximum

You are given an integer array arr and a window size k. A window of length k slides from the very left to the very right of the array, moving one position at a time. For each position of the window, you must report the maximum element visible inside it.

The output is an array of length n - k + 1 where the element at index i is max(arr[i], arr[i+1], ..., arr[i+k-1]).

<!-- sliding-window-diagram --> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 480 108" width="480" height="108" fill="none"> <text x="0" y="20" font-family="monospace" font-size="14" fill="#555">arr = [1, 3, -1, -3, 5, 3, 6, 7]</text> <text x="0" y="40" font-family="monospace" font-size="14" fill="#555">k = 3</text> <rect x="78" y="50" width="90" height="24" rx="4" stroke="#a00" stroke-width="2" fill="none"/> <text x="82" y="67" font-family="monospace" font-size="13" fill="#a00">1 3 -1</text> <text x="82" y="90" font-family="monospace" font-size="13" fill="#555">3 -1 -3</text> <rect x="78" y="76" width="90" height="24" rx="4" stroke="#a00" stroke-width="2" fill="none"/> <text x="222" y="80" font-family="monospace" font-size="13" fill="#555">…</text> <text x="320" y="67" font-family="monospace" font-size="13" fill="#555">5 3 6</text> <rect x="308" y="50" width="90" height="24" rx="4" stroke="#a00" stroke-width="2" fill="none"/> <text x="308" y="90" font-family="monospace" font-size="13" fill="#555">6 7</text> <path d="M88 56 L 82 64 L 86 64 L 86 74" stroke="#a00" stroke-width="1.5" fill="none"/> <path d="M308 56 L 314 64 L 310 64 L 310 74" stroke="#a00" stroke-width="1.5" fill="none"/> <text x="200" y="24" font-family="monospace" font-size="13" fill="#a00">window→max</text> </svg> <!-- /sliding-window-diagram -->
Examples
Input: [1,2,3]
Output: []
Hints

Sliding Window Maximum

You are given an integer array `arr` and a window size `k`. A window of length `k` slides from the very left to the very right of the array, moving one position at a time. For each position of the window, you must report the maximum element visible inside it.