Retrieval: which window is this?

Sliding Window

Retrieval: which window is this?

Two problems rebuilt cold, plus the distinction between maximizing and minimizing windows.

Key idea

The distinction that matters

Maximizing windows are legal while small and break when they grow. You shrink to restore legality, and you record after the shrink loop.

Minimizing windows are useful only once they are large enough. You shrink while they remain useful, and you record inside the shrink loop.

Same three lines of machinery, opposite placement of one line. Deciding which shape a new problem is, before writing anything, is most of what this unit was for.

Tip

A quick test

Ask whether a one-element window trivially satisfies the condition. If yes, you are usually maximizing and growing is what breaks things. If a one-element window is almost never enough, you are usually minimizing and growing is what fixes things.

Which shape does this problem want?

Find the shortest stretch of an array whose sum is at least a target, with all values positive. Which loop shape fits?

Longest Substring Without Repeating Characters, from scratch

You have solved this one before. Rebuild it from scratch without looking at your old submission. If the approach does not come back within a few minutes, that is the signal that it needs another pass.

Loading the workspace…

Container With Most Water, from scratch

You have solved this one before. Rebuild it from scratch without looking at your old submission. If the approach does not come back within a few minutes, that is the signal that it needs another pass.

Loading the workspace…
← Previous