When to use it
Sorted arrays, palindrome checks, pair/triplet sums, in-place partitioning, and cycle detection in linked lists.
Pattern
Maintain two indices that move toward a goal — often from opposite ends or as a fast/slow pair — so you solve the problem in one linear pass.
Sorted arrays, palindrome checks, pair/triplet sums, in-place partitioning, and cycle detection in linked lists.
Reference implementation in C#, Python, Java, JavaScript, and C++.
Turns many O(n²) nested loops into O(n) after a sort, which interviewers expect you to spot quickly.
Drill Two Pointers with Strings problems — filter the bank and solve 2–3 Easy/Medium items while saying the invariant out loud.
Related Strings problems — open any one and apply Two Pointers.
Longest Substring Without Repeating Characters
Sliding Window
Longest Palindromic Substring
DP / Expand
Zigzag Conversion
Simulation
String to Integer (atoi)
Parsing
Regular Expression Matching
DP
Integer to Roman
Greedy
Roman to Integer
Greedy
Longest Common Prefix
String
Letter Combinations of a Phone Number
Backtracking