Problem 3555 · Medium

Smallest Subarray to Sort in Every Sliding Window

For each window, compare it with its sorted copy; the first and last disagreeing offsets bound the shortest segment that repairs the whole window.

Open the interactive visualisation