Foundations
Linear Structures
Hashing
Array and String Patterns
Recursion, Search, and Sorting
Problem Solving Patterns
Algorithm Searching
Sorting Algorithms
Array Algorithms
Grid Algorithms
Linear Structure Algorithms
Hashing Algorithms
Recursion and Backtracking
Greedy Algorithms
Tree and Heap Algorithms
Graph Algorithms
Dynamic Programming Algorithms
String Algorithms
Math Algorithms
Keyboard ready
Space plays. Arrow keys step. R restarts.
LAB Two Pointer Pattern Lab
Patterns
Concept shape
Practice pattern
0
1
2
3
4
5
Definition
Use two indexes to scan from different positions without nested loops.
Step 1 / 5
Concept shape
Patterns Practice pattern
Two Pointer Pattern
Welcome to the Two Pointer Pattern concept lab. Use two indexes to scan from different positions without nested loops. The must know points are: Often requires sorted input. Pointers move based on a condition. Can reduce O(n^2) to O(n). The common operations are: left++, right--, compare pair, shrink region. The complexity shape is Usually O(n). Watch out for these pitfalls: Moving the wrong pointer. Forgetting that unsorted input may break the pattern. Related algorithms include Two Sum Sorted, Palindrome Check.
Concept details
Use two indexes to scan from different positions without nested loops.
Must know
- Often requires sorted input.
- Pointers move based on a condition.
- Can reduce O(n^2) to O(n).
Complexity
Usually O(n)
1.0x