Lesson 5: Arrays & two pointers
Picture a bookshelf where the books stand right next to each other: want the third one? Count three and jump straight to it. That's an array — reaching an item by index is O(1). Today we meet a neat trick, 'two pointers': instead of one marker scanning everything, you run two that move toward each o
Two pointers is like two people reading a long line from opposite ends — one starts at the beginning and the other at the end, and they move toward each other until they meet in the middle. You finish quickly that way, instead of each person reading the whole line alone.
- two pointers
- A pattern where two indices move over an array (from the ends inward or in the same direction) to solve a problem in one pass.
- in-place
- Changing the data inside the existing structure without allocating a new one — O(1) extra memory.
- contiguous memory
- Storing elements next to each other in memory, enabling O(1) index access and a cache-friendly scan.