CodeGround
DashboardProblemsInterviewsAssessmentsCourses
CodeGround
DashboardProblemsInterviewsAssessmentsCourses
The Technical Interview Course

0 of 170 lessons complete

  • Carrying one value forward
  • Expanding and shrinking a window
  • When validity is a computed quantity
  • Fixed-size windows and matching
  • Have and need
  • Retrieval: which window is this?

Sliding Window

27 / 170

Sliding Window/Lesson 6 of 6·About 40 min

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.

Quick check· 5 min

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?

Problem· 15 min

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.

Problem· 15 min

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.

PreviousHave and need
NextCold recall

0 of 4 parts complete