Another Sliding Window - find each `k-size` window the maximum num. from an integer array/list
I don't see any obvious improvements to your algorithm.
Tests:
Your &quot;main&quot; section seems to be checking if the algorithm works, but you can make better use of the examples provided with the original prompt.
Constraints:
The original prompt makes certain promises about the inputs. It's reasonable to just take those as assumptions, or (maybe better, depending on stuff) to make them explicit assertions, but there's no need to handle violating cases.
Typing:
You've got type-hints in your function signature.
That's great!
But in python the idea of &quot;types are comments that can't be wrong&quot; only holds if you actually use a type-checker. Trying mypy on your code gives an error that it can't figure out the type of q. The easiest fix for this would be to use the Deque from typing (or upgrade to python 3.9) so you can write q = Deque[int]().
Begging for microseconds:
You can save yourself some conditional checks by changing how you handle the first couple rounds: Start the loop with something in the deque, and slice off the head of the result-list at the end. On the other hand, trying to optimize at that level of granularity is easy to get wrong. I banged out an over-engineered version, but without benchmarking this is worthless.
from typing import List, Deque, Iterable, Tuple, Callable
from itertools import islice

def _window_func(k: int, q: Deque[Tuple[int, int]]) -&gt; Callable[[Tuple[int, int]], int]:
    def retval(pair):
        if q[0][0] == pair[0] - k:
            q.popleft()
        while q and q[-1][1] &lt; pair[1]:
            q.pop()
        q.append(pair)
        return q[0][1]
    return retval

def maxSliding(nums: List[int], k: int) -&gt; List[int]:
    assert nums
    assert 1 &lt;= k &lt;= len(nums)
    return list(islice(
        map(_window_func(k, Deque([(-1, nums[-1])])),
            enumerate(nums)),
        k - 1, None
    ))

tests = [([99,74,48,27,56,88,66,77,101], 3, [99,74,56,88,88,88,101]),
         ([1,3,-1,-3,5,3,6,7], 3, [3,3,5,5,6,7]),
         ([1], 1, [1]),
         ([1,-1], 1, [1,-1]),
         ([9,11], 2, [11]),
         ([4,-2], 2, [4])]

if __name__ == '__main__':
    for (l, k, result) in tests:
        try:
            actual = maxSliding(l, k)
            assert actual == result
        except:
            print(f'Offending test {(l, k, result)}, got {actual}')
            raise
    print(&quot;tests passed&quot;)
```