Skip to main content

Two Pointers and Sliding Window

2 lessonsAbout 12 minutesBeginner

This part of the DSA Tutorial runs from The Two Pointer Technique through to The Sliding Window Technique. There are 2 lessons here, and working through them takes about 12 minutes at a steady pace.

It follows on from Hash Maps and Sets, so finish that first if you have not already — the examples below assume you are comfortable with it.

Each lesson below says what it covers before you open it. Read them in order the first time; afterwards this page works as a index you can jump back into when you need to check one thing.

  1. 1The Two Pointer TechniqueTwo pointers turn nested loops into a single pass using no extra memory. Learn the two variants — opposite ends and same direction — and how to spot which problems allow them.
  2. 2The Sliding Window TechniqueSliding window solves every 'longest or shortest run that satisfies a condition' problem in one pass. Learn fixed and variable windows in JavaScript with worked examples.