iq.lab
Python starts when a code cell comes near or you run one

Module 4 · 4 lessons · about 7 hours 5 minutes

Two pointers and sliding windows

Pointers that close in from both ends, read and write pointers that edit a list in place, and windows that slide, grow and shrink over a list or string.

Lessons
0/4
Exercises
0/30
Code
0/4
Problems
0/15
Checkpoint
Not taken

Already comfortable with this? Take the checkpoint cold. If you pass, move on and come back only for what you missed.

  1. 1Two pointers from both endsPut one index at each end of a list or string and walk them toward each other. Every step proves that one item cannot be part of a better answer, so problems that seem to need every pair take one pass.2 h
  2. 2Read and write pointersTwo indexes walk one list in the same direction. `read` looks at every item, `write` marks where the next kept item goes, and everything before `write` is already the finished answer. Filled from the back, the same idea merges two sorted lists in place.1 h 35 min
  3. 3Fixed-size windowsA window is a block of k items in a row. Instead of adding up every window from scratch, slide it one step at a time, adding the item that enters on the right and subtracting the item that leaves on the left. O(n·k) work becomes O(n).1 h 10 min
  4. 4Windows that grow and shrinkWhen the question asks for the longest or shortest block that obeys a rule, one window answers it in one pass. The right edge moves every step, and the left edge catches up only when the rule forces it.2 h 20 min
  5. Checkpoint12 questions. Pass with 80% to finish the module.

Problems for this module

The lessons teach some of these step by step (each says which). The rest are practice: try each in its target time, and solved problems come back for spaced re-solves.

Next moduleStacks and queues