String Algorithms
Everything on SkillVeris tagged String Algorithms — collected across the glossary, study notes, blog, and cheat sheets.
23 resources across 1 library
Interview Questions(23)
What is a Trie?
A trie, or prefix tree, is a tree-based data structure that stores strings character by character along shared paths, letting you search, insert, and check pre…
Edit Distance Problem: How Would You Solve It?
Edit distance (Levenshtein distance) is solved with dynamic programming: dp[i][j] holds the minimum number of insertions, deletions, and substitutions to turn…
How Do You Find the Longest Common Subsequence?
The longest common subsequence (LCS) of two strings is the longest sequence of characters that appears in both strings in the same relative order but not neces…
How Do You Find the Longest Common Substring?
The longest common substring is the longest contiguous block of characters that appears identically in both strings, found with a 2D dynamic programming table…
What is a Suffix Tree?
A suffix tree is a compressed trie containing every suffix of a given string, built in O(n) time, that lets you answer substring existence, longest common subs…
What is the KMP String Matching Algorithm?
The Knuth-Morris-Pratt (KMP) algorithm finds all occurrences of a pattern in a text in O(n + m) time by precomputing a failure function (also called the longes…
What is the Rabin-Karp Algorithm?
Rabin-Karp finds pattern occurrences in a text by hashing the pattern and every equal-length substring of the text using a rolling hash, comparing hash values…
What is Manacher's Algorithm?
Manacher's algorithm finds the longest palindromic substring in a string in O(n) time by reusing previously computed palindrome-radius information from a mirro…
What is the Z-Algorithm for String Matching?
The Z-algorithm computes, for every position in a string, the length of the longest substring starting there that also matches a prefix of the whole string, bu…
Minimum Window Substring: How Do You Solve It?
Minimum window substring is solved with a variable-size sliding window and two hash maps: expand the right pointer until the window contains every required cha…
Longest Substring Without Repeating Characters
The longest substring without repeating characters is found with a sliding window and a hash map that stores the last seen index of each character: expand the…
How Do You Solve the Valid Parentheses Problem?
The valid parentheses problem is solved with a stack: push every opening bracket you encounter, and on every closing bracket, check that the stack's top is the…
How Would You Build Autocomplete Using a Trie?
You build autocomplete by inserting every candidate string into a trie character by character, then for a typed prefix you walk the trie to the node matching t…
How Do You Construct a Suffix Array?
A suffix array is built by generating every suffix of a string, sorting those suffixes lexicographically, and storing only their starting indices, which naive…
How Do You Find the Longest Palindromic Substring?
The expand-around-center approach finds the longest palindromic substring in O(n²) time and O(1) extra space by treating every index (and every gap between ind…
How Do You Solve the Palindrome Partitioning Problem?
Palindrome partitioning — splitting a string into the minimum number of cuts so every resulting piece is a palindrome — is solved with dynamic programming in O…
Word Break Problem: How Do You Solve It?
The word break problem — deciding whether a string can be segmented into a sequence of words from a given dictionary — is solved with dynamic programming where…
Decode Ways Problem: How Do You Solve It?
The decode ways problem — counting how many ways a digit string can be decoded to letters where "1" maps to "A" through "26" maps to "Z" — is solved with dynam…
Knuth-Morris-Pratt vs Rabin-Karp: What is the Difference?
KMP guarantees O(n + m) worst-case time by precomputing a failure function that avoids re-scanning matched characters after a mismatch, while Rabin-Karp uses r…
What is the Aho-Corasick Algorithm?
Aho-Corasick is a multi-pattern string-matching algorithm that builds a trie of all patterns augmented with failure links, letting it search text for every occ…
What is a Suffix Automaton?
A suffix automaton is the smallest deterministic finite automaton that accepts exactly every suffix of a given string, built online in O(n) time and space, and…
How Do You Solve the Longest Repeated Substring Problem?
The longest repeated substring problem asks for the longest substring that occurs at least twice, possibly overlapping, in a given string, and the standard eff…
What is String Hashing and How Is It Used?
String hashing converts a string into a fixed-size numeric fingerprint using a polynomial rolling hash, typically computed modulo a large prime, so that two eq…