← All challenges
medium★ Curatedmore-itertools/more-itertools · v11.1.0

Preserve the first matching item in sliding-window extrema

Try this bug with AI

Fix it in the original repo with an AI agent and get feedback on how you worked.

2 free rounds each week

Round mode
  • Time limit60 min
  • Token budgetup to 1M
  • Worth up to210 XP
Sign up or sign in to start

Read the sample report

From a simulated Django round

You changed code before reproducing the bug.

Run the failing test before the first edit, so you know the failure you are fixing and can tell when it is gone.

Problem statement

The sliding-window forms of running_min and running_max sometimes switch to a newer item even though an earlier item in the window is equally small or equally large. This matters for callers who care which original object was selected, even when the values compare equal.

Match Python's min and max on each current window: ties should keep the earliest eligible item. Once that item leaves the window, select the earliest remaining eligible item. Preserve the existing iterator behavior, including partial starting windows and inputs with no window limit.

The environment starts at commit 301c957c8a50 (more-itertools/more-itertools 11.1.0). Grading uses hidden tests for the fix and existing behavior.

An upstream fix is publicly available. An assistant may already recognize this task. For a cold rehearsal, pick another exercise if you know the fix.