Two pointers, sliding windows, hashmaps, and pattern matching applied to characters and substrings.
Converge from both ends to compare characters without extra space.
O(n)naïve O(n²)When to reach for it
Spot it in the prompt
Look for problem descriptions mentioning the need to compare characters from both ends of the string or to traverse the string simultaneously with two pointers. Phrases like 'pair of characters,' 'triplet of characters,' or 'sorted string' indicate the potential application of two pointers.
How to solve it
Animation: Two Pointers techniqueSet pointers at both ends, skip non-alphanumeric characters, and compare mirrored letters case-insensitively until the pointers cross.
Open full solutionA stretchy window scans substrings in one linear pass.
O(n)naïve O(n²)When to reach for it
Spot it in the prompt
Problems involving contiguous substrings often hint at the use of the sliding window technique. Look for phrases like 'substring,' 'contiguous characters,' 'sliding window,' or hints that a window needs to slide through the string.
How to solve it
Animation: Sliding Window techniqueExpand the right edge until all target counts are covered, then shrink the left edge to minimize the still-valid window.
Open full solutionCount and look up characters in constant time.
O(n)When to reach for it
Spot it in the prompt
Phrases like 'count,' 'frequency,' 'group,' or 'exist' suggest the potential use of hashmaps. Problems requiring counting occurrences, grouping similar characters, or checking for the presence of specific characters often indicate the application of hashmaps.
How to solve it
Animation: Hashmaps techniqueUse a sorted-character or frequency-count signature as the map key, bucketing every string that shares the same signature.
Open full solutionReverse, parse, and rebuild strings character by character.
When to reach for it
Spot it in the prompt
Problem descriptions mentioning operations like 'manipulate,' 'convert,' 'parse,' or specific string operations (e.g., reversing, splitting) indicate the need for string manipulation techniques.
How to solve it
Animation: String Manipulation techniqueSwap characters from both ends inward, mutating the character array in place until the pointers meet.
Open full solutionMatch text against patterns with wildcards and DP.
O(n·m)When to reach for it
Spot it in the prompt
Look for phrases like 'pattern,' 'validation,' 'matching,' or specific patterns (e.g., email addresses, phone numbers). Problems requiring validation of input strings against specific patterns or constraints often suggest the application of regular expressions.
How to solve it
Animation: Regular Expressions techniqueFill a DP table over string and pattern indices, treating '*' as zero-or-more of its preceding element.
Open full solutionFDE Coach is a cohort-based program in frontend, backend, AWS, and AI where you build real products and get referred to 200+ hiring partners. The free live workshop is the fastest way to see how we teach.
750+ engineers trained · frontend, backend, AWS & AI