What it is
"String" is a category tag, not one technique: it covers any problem where the input is text and the core work is walking, comparing, or rewriting characters. Under that umbrella you find two-pointer scans (palindrome checks), stack-based matching (balanced brackets), interval or prefix dynamic programming (palindromic substrings, edit distance), hand-written parsers (integer conversion, calculators), hash-based grouping (anagrams), and graph search over an implicit word graph (word ladders). What ties them together is the data shape, not the algorithm, so the first job on any string question is naming which of those techniques actually applies.
When it applies
- The problem's real technique is genuinely about character-level structure: order, symmetry, matching pairs, or transforming one string into another.
- It does not apply as a technique in its own right when a more specific pattern already covers the mechanism — a fixed-size or shrinking/growing contiguous run over a string is sliding-window, and grouping strings by a derived key is hash-map with a string-shaped key. Reach for those named patterns first and use "string" only as the umbrella when you're scoping which techniques to consider.
- It is the right frame when you must design a hand-rolled parser or serialization format (state machine over characters) rather than call a library function, since the library call is usually disallowed by the prompt.
Tells in the problem
- "Reads the same forwards and backwards" — palindrome, solved by two pointers or center-expansion, not by building a reversed copy unless O(n) space is fine.
- "Every opening X must be closed by a matching X, in the right order" — bracket/tag matching, solved with a stack.
- "Parse the following string according to these rules" or "implement your own version of X" — a state machine you write by hand, stage by stage.
- "The minimum number of operations to turn one string into another" — edit distance, a 2D DP over prefix pairs.
- "Group these words/strings by some shared property" — the property is a derived key; this is really hash-map, not a string-specific trick.
The classic mistake
Picking a technique before naming what "matches" or "differs" means at the character level is the recurring error, and it surfaces three lines in, once the chosen structure can't express the rule. A common example: reaching for a plain delimiter to join strings for later splitting, forgetting the delimiter itself can appear inside the data — the fix (length-prefixing, or careful escaping) only becomes obvious once you ask "what if the separator is already in the input?" before writing any code. Another version is writing a palindrome check that allocates a cleaned copy when the interviewer explicitly wants O(1) space, having jumped to code before confirming the space constraint. Pause after reading the prompt and state, out loud, what operation you're optimizing (comparison, matching, transformation) before choosing the structure.
Questions to start with
- Valid Parentheses — a stack driven purely by character-level matching rules; the cleanest illustration of "what does a match mean here."
- Valid Palindrome — two pointers with a filtering rule layered on top, and the first place O(1) space becomes the real ask.
- Encode and Decode Strings — forces you to design a framing scheme rather than reach for a delimiter, which is where the "what if my separator is in the data" trap lives.
- String to Integer (atoi) — a hand-written multi-stage parser where ambiguous inputs are the whole point.
- Edit Distance — the string version of a 2D DP, once character equality alone isn't enough to decide the answer.