Coding Interview Prep · 70 min · Python
Arrays & Strings: Two Pointers, Sliding Window & Hash Maps
90% of interview array problems are one of four patterns. Learn the patterns, not the problems.
Hiring signal: Recognises the right pattern immediately and codes it cleanly under time pressure
What you will learn
- Identify and apply the two-pointer pattern for pair/subarray problems
- Use a sliding window for contiguous-subarray optimisation problems
- Build prefix-sum arrays for range-query and balance problems
- Use hash maps to reduce O(n²) scans to O(n)
- State time and space complexity for every solution
The Problem
LeetCode has 2,000+ problems. Memorising solutions doesn't scale. What scales is recognising the pattern in the problem — and array/string problems almost always map to one of four: two pointers, sliding window, prefix sums, or hash map. Internship and new-grad ML roles at large companies screen with exactly these patterns at medium difficulty. Knowing them cold is table stakes.
The Concept
Why Patterns, Not Problems
The human brain can't memorize 2,000 solutions. But it can memorize 4-5 patterns and learn to recognize which one applies. This is how strong competitive programmers and interviewers think — they don't recall a specific problem, they identify the structural property of the input and map it to a technique.
For arrays and strings, the key structural properties are:
- Is the data sorted? → Two pointers can exploit ordering to eliminate brute-force pairs
- Is there a contiguous sub-range with a constraint? → Sliding window maintains a valid window while expanding/contracting
- Are there repeated range-sum queries? → Prefix sums precompute cumulative sums for O(1) range queries
- Are you looking up complements or frequencies? → Hash maps trade space for O(1) lookups
Every array/string interview problem you encounter will be a combination of these. The skill is not knowing 200 problems — it's recognizing which pattern matches the problem in front of you within 30 seconds of reading it.
Unlock the full lesson
You've read the first 2 sections. The rest of this lesson covers The Patterns, Interview Discipline, Ship It, Use It, Evaluation, Exercises, Key Terms, Common Pitfalls, Interview Framing — plus a hands-on lab, quiz, and project artifact.
Create a free account to unlock Phase 0 and Phase 1 of every course — no credit card.
Browse all courses · View pricing · DeVenture Academy