Longest String Chain
Problem Statement
You get a list of words made of lowercase letters. Word A is a predecessor of word B when you can insert exactly one letter into A, at any position, and get B.
A chain is a list of words where each word is a predecessor of the next one. A single word is a chain of length 1. Return the length of the longest chain you can make from the list.
words, a list of words. The list is not sorted.
The length of the longest chain of words.
One longest chain is a → ba → bda → bdca. Each word is the one before it with one letter inserted.
The chain xb → xbc → cxbc → pcxbc → pcxbcf adds one letter at each step.
Neither word is a predecessor of the other, so the longest chain has one word.
- • 1 ≤ words.length ≤ 1000
- • 1 ≤ words[i].length ≤ 16
- • words[i] consists only of lowercase English letters.
Pattern Recognition Clues
Recognising these key signals in the problem description immediately identifies the pattern:
Approach Complexity Ladder
Recursion: the longest chain ending at a word tries every word that can come before it, with no memory
Sort by length; best[i] = 1 + best[j] for each earlier word j that is a predecessor of words[i]
Sort by length; for each word, try its deletions in a hash map of best chain lengths
Let chainEnd(w) be the longest chain that ends with word w. It is 1 plus the largest chainEnd over the words that are predecessors of w, or just 1 if there are none. Try every word in the list, and do not remember any answer. The answer is the largest chainEnd over all words.
Recognition rule for this sub-pattern:
Unlock Complete Visual Walkthrough & Optimal C++
The interactive animated dry-run player, optimized C++ implementation, state invariant derivations, and edge-case breakdown for this question are part of Brute2Best Pro. The anchor question of every sub-pattern is completely free.
First anchor question per pattern, Part 1 LLD & Module 1 C++ basics are 100% Free forever.
How this concept connects to System Design & C++ Systems
Top engineering interviews test whether you understand how algorithms like DP — Longest Increasing Subsequence translate into production architectures and low-level memory mechanics.
Foundations: Object-Oriented Principles in C++23
Class invariants, pure virtual interfaces, and RAII smart pointers.
Food Delivery System (Zomato Architecture)
Real-world machine coding application of algorithms and design patterns.
Pointers vs References Deep Dive
Pointer arithmetic and memory layout under the hood.
Virtual Method Table (vtable) & Memory Layout
Polymorphism, vptr overhead, and multiple inheritance in memory.