Master advanced string algorithms: KMP failure function for O(n) pattern matching, Z-algorithm for all prefix matches, Rabin-Karp rolling hash, and suffix arrays for substring queries.
Implement KMP string search: build the failure function (LPS array) in O(m) then search in O(n). Never re-examines matched characters unlike naive search.
The Z-algorithm computes Z[i] = length of the longest substring starting at i that matches a prefix of the string. O(n) time, elegant and powerful for pattern search.
Build a suffix array in O(n log²n) using doubling sort. Enables O(m log n) substring search, longest common substring, and number of distinct substrings.
Group anagrams, find anagram indices, and count anagram occurrences. Three approaches: sort key O(nk log k), frequency tuple O(nk), and sliding window O(n+k).
Word Search I and II solved with DFS backtracking. Word Search II uses a Trie to prune the search space from O(N·4^L) per word to O(N·4^L) total for all words.
Design an encode/decode scheme for a list of strings. Length-prefix encoding (4-byte header per string) is collision-proof unlike delimiter-based approaches.
Add minimum characters to the front of a string to make it a palindrome. KMP trick: concatenate s + '#' + rev(s), find the LPS value at the last position.
Count the number of distinct substrings using the suffix array and LCP array. Total substrings minus sum of LCP values gives distinct count in O(n log n).
High-frequency string problems from Meta and Google interviews: valid parentheses, longest substring without repeating characters, zigzag conversion, and string to integer.
Aho-Corasick automaton matches all patterns simultaneously in O(n+m+z) where z is the number of matches. Builds failure links on a trie for efficient multi-pattern search.