DSA Lab
Two pointers and sliding window
Two indexes move through an array, and each step moves one of them in a direction that can never skip an answer. That turns many 'check every pair' or 'check every range' problems from O(n²) into O(n).
Two pointers and sliding window: how it works
In this tool: pair sums and best windows in O(n). Put in your own values and watch it change. Each operation runs one step at a time and says in plain words what happened, with its calculation worked out. The code is shown in Python, C, C++ or Java with the line that just ran marked, and an Understand it panel gives the idea, why it works, the cost of each operation, common mistakes and a short quiz.
Lessons that use it
- Two pointers and sliding windows (Python)Solve list problems in one pass by moving two positions through the data.
- Two pointers (Interview Prep)Two indexes moving through a sorted list or a string: pair sums, palindromes, removing duplicates in place, three sum, and the container with the most water.
- Sliding windows (Interview Prep)A window over a list or string that slides instead of restarting: fixed-size windows, the longest substring without repeats, and the smallest window that meets a condition.
- Two pointers and sliding windows (Competitive)Two indexes that only move forward turn many O(n²) searches into O(n): pair sums in a sorted array, and windows.