Open the context
Choose the project folder and name the files or behavior involved.
Find the maximum in each complete fixed-width numeric window. Check repeated maxima, negative values and width boundaries, rejecting non-finite values and widths outside the input length.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
from collections import deque
from math import isfinite
def window_max(values, width):
if type(width) is not int or not 1 <= width <= len(values):
raise ValueError("width")
if not all(map(isfinite, values)): raise ValueError("finite values")
queue, result = deque(), []
for i, value in enumerate(values):
while queue and queue[0] <= i - width: queue.popleft()
while queue and values[queue[-1]] <= value: queue.pop()
queue.append(i)
if i >= width - 1: result.append(values[queue[0]])
return resultThe example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.