String questions come in many costumes — palindromes, anagrams, brackets, windows, matching, editing — but underneath, most of them are one of nine moves. Learning to recognise the move from the wording is what makes a new question feel familiar.
Three questions to ask
What's the alphabet?"Lowercase English letters" means you can count with an array of 26. "Any characters" means a hash map.
Can I change the input? If the string is handed over as a character array (or you're in C++), you may work in place. Otherwise, you'll build a new string — with a builder.
What's being asked? A yes/no about the whole string, the best substring, all combinations, the position of a pattern, or a minimum/maximum between two strings — each points to a pattern below.
The 9 patterns, from easiest to hardest
Two pointers — "reverse", "palindrome", "in place". One pointer at each end, moving inwards, comparing or swapping. Reverse String, Valid Palindrome, Valid Palindrome II, Reverse Words in a String.
Frequency counting — "anagram", "same characters", "first unique", "can you build X from Y". Count each character (array of 26 or a hash map) and compare the counts. Valid Anagram, First Unique Character, Group Anagrams.
Scan and build — "compress", "convert", "parse", "common prefix". Walk the string once, keep a little state, and write the answer as you go. Longest Common Prefix, String Compression, String to Integer (atoi).
Stack — "backspace", "remove adjacent", "valid brackets", "undo". The newest character is the one that can be cancelled. Backspace String Compare, Remove All Adjacent Duplicates II, Minimum Remove to Make Valid Parentheses.
Sliding window — "longest / shortest substring with …", "contains all of", "anagram of p inside s". Grow the right edge, shrink the left edge, keep counts of what's inside. Find All Anagrams, Longest Repeating Character Replacement, Minimum Window Substring.
Expand around the centre — "palindromic substring". Every palindrome has a middle; grow outwards from each of the 2n - 1 possible middles. Palindromic Substrings, Longest Palindromic Substring.
Backtracking — "all possible", "generate every", "combinations". Build the string one choice at a time, and undo the choice to try the next. Letter Combinations of a Phone Number, Generate Parentheses.
String matching — "find the pattern", "is it made of repeats", . The KMP prefix function finds a pattern in O(n + m) instead of O(n · m). First Occurrence, Repeated Substring Pattern, Shortest Palindrome.
Substring or subsequence?
This one word changes the pattern, so read it carefully. A substring is a contiguous block ("ell" in "hello") — think two pointers, sliding window or expand-around-centre. A subsequence keeps the order but may skip characters ("hlo" in "hello") — that usually means dynamic programming.
Choosing by the size of the input
n up to about 20 — trying every possibility is fine: backtracking, O(2ⁿ) or similar.
n up to a few thousand — O(n²) works: expand around every centre, a DP table over two strings.
n up to 10⁵ or more — you need O(n) or O(n log n): two pointers, one scan, a sliding window, counting, KMP.
The rest of the course takes the patterns one at a time, in exactly this order, each through the interview questions that use it most.
Dynamic programming on strings — "minimum edits", "longest common subsequence", "can it be split into words". A table over prefixes of one or two strings, each cell built from its neighbours. Longest Common Subsequence, Word Break, Edit Distance.