DSA
Master Two Pointer Patterns: 7 Techniques for Coding Interviews
Master 7 two-pointer techniques used in Google, Amazon, and Meta interviews. Learn patterns with 34 curated problems, AI-powered hints, and instant feedback.

You've spent 100+ hours grinding LeetCode. You've memorized solutions to Two Sum, 3Sum, and Container With Most Water. But when a new array problem appears in your Amazon interview, you freeze. The question looks familiar, but you can't quite figure out the approach.
Sound familiar?
The problem isn't practice—it's pattern recognition. Most engineers memorize solutions instead of understanding the underlying pattern. That's why after solving 200 problems, they still panic when they see a variation.
Here's the truth: You don't need to solve 500 problems. You need to master 7 two-pointer patterns that appear in 15% of all FAANG array interviews and unlock countless coding problems.
What You'll Learn
By the end of this guide, you'll master:
✅ The 7 two-pointer sub-patterns that solve everything from palindromes to cycle detection ✅ Pattern recognition skills to tackle any two-pointer problem in interviews ✅ 34 curated practice problems asked at Google, Amazon, Facebook, Microsoft, and Bloomberg ✅ When to use each pattern with clear mental models and recognition triggers ✅ Common pitfalls that trip up even experienced engineers ✅ A practice roadmap to go from beginner to interview-ready in 2-3 weeks
What Are Two Pointer Patterns?
Think of Two Pointers as a pair of dancers—sometimes mirroring each other, sometimes moving apart, but always in sync with the rhythm of the data.
Instead of using nested loops that give you O(n²) time complexity, two pointers use coordinated traversal to solve problems in O(n) time. You maintain two positions in your data structure (array, string, linked list) and move them based on specific conditions.
The core insight: When you find yourself thinking "I need to check every pair/combination," ask yourself: "Can two coordinated pointers replace this nested loop?"
Why This Pattern Matters
Two pointer techniques are fundamental to software engineering interviews because they:
- Optimize Space & Time: Convert O(n²) brute force to O(n) elegant solutions
- Test Problem-Solving Skills: Interviewers love them because they require thinking, not memorization
- Appear Everywhere: 15%+ of FAANG array/string questions use two pointers
- Build Foundation: Understanding two pointers helps with sliding window, binary search, and other patterns
Companies that frequently ask two-pointer questions: Google, Amazon, Microsoft, Facebook, Bloomberg, Apple, Goldman Sachs, LinkedIn
The 7 Two Pointer Sub-Patterns
Let's break down the seven variations of two-pointer technique. Each has distinct use cases, movement patterns, and problem types.
Pattern 1: Converging Pointers (Sorted Array Target Sum)
What it is: Two pointers start at opposite ends of a sorted array and move toward each other based on comparisons.
Key insight: In a sorted array, if the sum is too large, decrease the right pointer. If too small, increase the left pointer. This exploits the sorted order for O(n) pair/triplet finding.
When to use:
- Finding pairs/triplets that meet specific conditions
- Target sum problems in sorted arrays
- Maximizing/minimizing with sorted data
Essential Problems
Easy:
- Two Sum - Amazon, Google, Apple, Adobe, Microsoft
- Two Sum II - Input Array Is Sorted - Classic converging pointer example
- Squares of a Sorted Array - Facebook, Uber, Google
- Is Subsequence - Bloomberg
- Intersection of Two Arrays - Facebook, Amazon, Bloomberg
Medium: 6. Container With Most Water - Amazon, Google, Microsoft, Facebook ⭐ 7. 3Sum - Amazon, Facebook, Microsoft, Bloomberg ⭐ 8. 3Sum Closest - Amazon, Apple, Google, Facebook 9. 4Sum - Amazon, Bloomberg 10. 3Sum Smaller - IBM, Citadel 11. Boats to Save People - Roblox, Paypal
💡 Pro Tip: Container With Most Water is a perfect interview question because it looks like it needs nested loops, but converging pointers solve it in O(n). Practice explaining why we can safely move pointers without missing the optimal solution.
⚠️ Common Mistake: Forgetting to handle duplicates in 3Sum/4Sum. Always skip duplicate values after finding a valid triplet/quadruplet.
Example - Two Sum II Pattern:
PYTHON
Pattern 2: Expanding From Center (Palindromes)
What it is: Pointers start at a center point and expand outward to find symmetric patterns.
Key insight: Every palindrome has a center (either one character or between two characters). By expanding from each possible center, you can find all palindromic substrings in O(n²) time—much better than the naive O(n³) approach.
When to use:
- Finding palindromic substrings
- Checking symmetry from a pivot point
- Any problem requiring "expand around center" logic
Essential Problems
Medium:
- Longest Palindromic Substring - Amazon, Microsoft, Wayfair, Facebook ⭐
- Palindromic Substrings - Facebook, Goldman Sachs, Google
💡 Pro Tip: Remember to check BOTH odd-length (single center) and even-length (two-character center) palindromes. Many candidates miss even-length cases.
Example - Expand Around Center Pattern:
PYTHON
Pattern 3: Fast & Slow Pointers (Cycle Detection)
What it is: Two pointers move at different speeds through a sequence. The fast pointer moves 2 steps while the slow pointer moves 1 step.
Key insight: If there's a cycle, the fast pointer will eventually "lap" the slow pointer and they'll meet. This is Floyd's Cycle Detection Algorithm (also called the "tortoise and hare" algorithm).
When to use:
- Detecting cycles in linked lists or sequences
- Finding the start of a cycle
- Middle of linked list problems
- Any problem where "different speeds" reveal hidden properties
Essential Problems
Easy:
- Linked List Cycle - Microsoft, Apple, Amazon, Goldman Sachs ⭐
- Happy Number - Apple, Adobe, ByteDance
Medium: 3. Find the Duplicate Number - Microsoft, Amazon, Apple, Google ⭐
💡 Pro Tip: Fast & slow pointers aren't just for linked lists! "Happy Number" uses the same technique on number sequences. Train yourself to see the pattern beyond the data structure.
⚠️ Common Mistake: In "Find the Duplicate Number," candidates often use hash sets. The constraint says O(1) space—that's your hint to use cycle detection.
Example - Cycle Detection Pattern:
PYTHON
Pattern 4: Fixed Separation (Nth Node from End)
What it is: One pointer leads by a fixed distance, then both pointers move together at the same speed.
Key insight: To find the nth node from the end in a single pass, advance one pointer n steps ahead, then move both pointers together. When the leading pointer reaches the end, the trailing pointer is at the nth position from the end.
When to use:
- Finding nth element from the end without knowing length
- Middle of linked list problems
- Any "from end" query that requires single-pass solution
Essential Problems
Easy:
- Middle of the Linked List - Microsoft
Medium: 2. Remove Nth Node From End of List - Facebook, Amazon, Microsoft, Bloomberg ⭐ 3. Delete the Middle Node of a Linked List
💡 Pro Tip: For "Remove Nth From End," use a dummy node to handle edge cases (like removing the head). This is a common interview trick that makes your code cleaner.
Example - Nth From End Pattern:
PYTHON
Pattern 5: In-Place Array Modification
What it is: One pointer reads elements sequentially while another pointer writes/places elements at correct positions. This enables in-place modifications without extra space.
Key insight: Minimize space by reusing the input array. The "read" pointer scans through elements, while the "write" pointer places elements in their final position.
When to use:
- Removing duplicates from sorted arrays
- Moving elements (like moving zeros to end)
- Partitioning arrays (like sorting colors)
- Any in-place array manipulation
Essential Problems
Easy:
- Remove Duplicates from Sorted Array - Google, Facebook, Amazon, Microsoft ⭐
- Remove Element - Adobe, Amazon, Oracle
- Move Zeroes - Facebook, Bloomberg, Microsoft, Adobe
- Sort Array By Parity - Capital One, VMware
Medium: 5. Remove Duplicates from Sorted Array II - Microsoft 6. Sort Colors - Microsoft, Facebook, eBay, Amazon ⭐ 7. String Compression - Goldman Sachs, Microsoft, Apple 8. Separate Black and White Balls 9. Move Pieces to Obtain a String
💡 Pro Tip: "Sort Colors" (Dutch National Flag problem) is a classic that uses THREE pointers. It's a favorite at Microsoft and Facebook because it tests whether you truly understand partitioning logic.
⚠️ Common Mistake: In "Move Zeroes," many candidates overwrite elements. Remember: we're moving, not removing. Preserve all non-zero elements in order.
Example - In-Place Modification Pattern:
PYTHON
Pattern 6: String Comparison with Backspaces
What it is: Reverse traversal with two pointers to simulate character deletion (backspace) operations.
Key insight: Process strings backward to handle deletions. When you encounter a backspace character (#), increment a skip counter. When skip > 0, ignore characters.
When to use:
- String comparison with deletion operations
- Simulating backspace/undo operations
- Problems requiring "final result" after deletions
Essential Problems
Easy:
- Backspace String Compare - Facebook, Google, Amazon, Oracle ⭐
- Crawler Log Folder - Mercari
💡 Pro Tip: The optimal solution uses O(1) space by traversing strings backward. Many candidates jump to using stacks (O(n) space). Practice the two-pointer approach for follow-up questions.
Example - Backspace Comparison Pattern:
PYTHON
Pattern 7: String Reversal
What it is: Pointers at opposite ends swap characters and move inward toward each other.
Key insight: The simplest two-pointer pattern. Start at both ends, swap elements, move pointers toward center until they meet.
When to use:
- Reversing entire strings or arrays
- Reversing specific portions (like words in a string)
- Reversing only certain characters (like vowels)
Essential Problems
Easy:
- Reverse String - Apple, Microsoft, Goldman Sachs, Amazon ⭐
- Reverse Vowels of a String - Facebook, Google, Amazon
- Reverse String II - Apple
Medium: 4. Reverse Words in a String - Microsoft, Oracle, LinkedIn, Apple
💡 Pro Tip: "Reverse Words in a String" combines multiple techniques: trim spaces, reverse entire string, then reverse each word. It's a great problem to demonstrate composing simple patterns into complex solutions.
Example - String Reversal Pattern:
PYTHON
How to Master Two Pointers on Thita.ai
Learning patterns is one thing. Applying them under pressure is another.
That's where Thita.ai's AI-powered practice platform comes in:
1. Pattern-Based Problem Sets
Our DSA Patterns Sheet organizes two-pointer problems by sub-pattern, so you can master one technique at a time instead of random grinding.
2. AI Hints & Instant Feedback
Stuck on a problem? Get AI-powered hints that guide you toward the pattern without spoiling the solution. It's like having a senior engineer pair programming with you.
3. Real Interview Simulation
Practice two-pointer problems in our AI Mock Interview environment. Get asked follow-up questions, explain your approach, and receive feedback on your communication—just like a real FAANG interview.
4. Track Your Progress
Your Dashboard shows which patterns you've mastered and which need more work. No more guessing whether you're ready.
Practice on Thita.ai: Start with Two Pointer Problems →
Your Two Pointer Learning Roadmap
Here's how to go from beginner to interview-ready in 2-3 weeks:
Week 1: Foundations (Easy Problems)
Goal: Build muscle memory with core patterns
Day 1-2: Converging Pointers
Day 3-4: In-Place Modification
Day 5-6: String Reversal
Day 7: Fast & Slow Pointers
Week 2: Intermediate (Medium Problems)
Goal: Handle variations and edge cases
Day 8-10: Advanced Converging
Day 11-12: Complex In-Place
Day 13-14: Palindromes & Cycles
Week 3: Mastery & Mixed Practice
Goal: Recognize patterns instantly
Day 15-17: Mixed problem sets (don't look at pattern category)
- Randomly select 3-4 problems per day
- Focus on identifying which pattern to use within 1-2 minutes
Day 18-19: Timed practice
- Solve problems under 25-30 minute time constraints
- Practice explaining your approach out loud
Day 20-21: Mock interviews
- Use Thita.ai's AI Mock Interview
- Get comfortable with follow-up questions and optimization discussions
💡 Pro Tip: After solving each problem, ask yourself: "Which pattern did I use? Could I have solved this differently? What was the key insight?" This reflection cements pattern recognition.
Common Two Pointer Pitfalls (And How to Avoid Them)
⚠️ Mistake 1: Not Considering Edge Cases
Problem: Forgetting to handle empty arrays, single elements, or duplicates.
Solution: Before coding, list out 3-4 edge cases. For two pointers, always consider: empty input, single element, all same elements, all different elements.
⚠️ Mistake 2: Off-by-One Errors
Problem: Using left <= right when you should use left < right (or vice versa).
Solution: Draw out small examples (3-4 elements) and trace your pointer movements manually. This reveals boundary issues quickly.
⚠️ Mistake 3: Not Utilizing Sorted Property
Problem: Applying two pointers to unsorted data when the pattern requires sorted input.
Solution: Many two-pointer patterns (especially converging) require sorted arrays. If your input isn't sorted, ask: "Should I sort first?" The O(n log n) sort + O(n) two-pointer is often better than O(n²) brute force.
⚠️ Mistake 4: Overcomplicating with Hash Maps
Problem: Reaching for hash maps when two pointers would be simpler and more space-efficient.
Solution: When you see "pair," "triplet," or "target sum" in sorted arrays, think two pointers first. Hash maps are great, but two pointers are more elegant for these cases.
⚠️ Mistake 5: Mixing Up Fast/Slow Pointer Initialization
Problem: Starting both pointers at head instead of head and head.next for cycle detection.
Solution: For cycle detection, fast must start one step ahead. Otherwise, they'll always be equal and you'll immediately return true.
Why Two Pointers Beat Brute Force
Let's look at a concrete example: Container With Most Water
Brute Force Approach (check every pair):
PYTHON
Time Complexity: O(n²) Space Complexity: O(1)
Two Pointer Approach:
PYTHON
Time Complexity: O(n) Space Complexity: O(1)
The Insight: We can safely discard half the search space at each step. If the left height is shorter, moving the right pointer inward will never give us a larger area (width decreases, height stays same or gets worse). So we move the left pointer.
This is the magic of two pointers: intelligent elimination of impossible solutions.
Beyond LeetCode: Real-World Applications
Two pointer patterns aren't just for interviews—they power real systems:
1. Data Deduplication (In-Place Modification)
- Log processing pipelines at Bloomberg use two-pointer techniques to deduplicate sorted event streams without extra memory
- Microsoft's data compression algorithms use in-place compaction
2. String Matching (Fast & Slow)
- LinkedIn's search infrastructure uses two-pointer approaches for fuzzy string matching
- Google's spell-checker employs similar techniques for edit distance calculations
3. Load Balancing (Converging Pointers)
- Amazon's load balancers use two-pointer logic to pair servers with requests based on capacity
- Meta's resource allocation systems optimize using similar pairing algorithms
4. Network Protocol Verification (Palindromes/Symmetry)
- Packet validation in network stacks uses symmetry checking
- Cryptographic hash verification employs similar bidirectional scanning
Understanding these real-world applications helps you explain to interviewers: "This isn't just a coding puzzle—it's how we'd actually build production systems."
Conclusion: From Memorization to Mastery
You started this guide probably thinking two pointers was just "use two indices instead of one." Now you understand it's actually seven distinct patterns, each with specific use cases, movement rules, and optimization insights.
The difference between memorizing and mastering:
- ❌ Memorization: "Oh, this is Two Sum, I move left and right pointers"
- ✅ Mastery: "This is a target-finding problem on sorted data, so I'll use converging pointers because each comparison eliminates half the remaining search space"
With 7 patterns and 34 curated practice problems, you now have a structured path to mastery. No more random LeetCode grinding. No more panic when you see a variation.
Your next steps:
- Bookmark this guide for reference
- Practice the Easy problems first to build confidence
- Use AI Mock Interviews to test pattern recognition under pressure
- Track your progress on your Dashboard
Remember: Google doesn't hire people who memorize 500 solutions. They hire people who recognize patterns and adapt them to new problems.
Ready to master two pointers? Start practicing on Thita.ai →
Related Articles
Looking to expand your pattern knowledge? Check out these guides:
- Master 90+ DSA Patterns - Complete roadmap for coding interviews
- Best AI Interview Prep Tools 2026 - Compare top platforms
- [How to Ace FAANG Coding Interviews](/blog/interview/how-to-prepare-for-coding-interviews-from-scratch-in-2026-a-complete-beginner-guide - Interview preparation strategies
External Resources
Want to dive deeper? Here are some authoritative resources:
- LeetCode: Two Pointers Problems
- Thita.ai Practice: Two Pointer Pattern Sheet
- Interactive Learning: AI-Powered Mock Interviews
Looking for personalized AI coaching on two-pointer problems? Try Thita.ai's AI Mock Interview and get instant feedback on your approach, code quality, and communication skills. Used by 10,000+ engineers preparing for Google, Amazon, Meta, and Microsoft interviews.