Python Quest

Track 16 · Lesson 8 of 12

Two pointers and sliding windows

Walk through sequences with two indexes instead of nested loops: find pairs in sorted data and compute running windows such as moving averages and longest streaks in O(n).

About 50 minAdvanced4 exercises

You will be able to

  • Find pairs in sorted data by moving two pointers towards each other
  • Compute fixed-size window results by updating a running total instead of re-summing
  • Use a variable-size window that grows and shrinks to find the longest valid stretch
  • Argue why each technique is O(n): every pointer only moves forward

Included with a Formula Quest membership

It has 4 graded exercises with feedback, hints and solutions. Python Quest is included in Formula Quest memberships that cover Python; membership and billing are managed on Formula Quest.

View Formula Quest memberships

Tracks 1 and 2, the first lesson of every track, the playground and the dataset library are free.