Dynamic Programming21 sections · 916 units
Open in Course

LeetCode 1048 Longest String Chain - Problem Statement

LIS on string predecessors

Solve Longest String Chain from LeetCode. Word A is a predecessor of word B if you can insert exactly one letter into A to get B. Find the longest chain of words where each word is a predecessor of the next.

Hint: Sort words by length. Use a HashMap where dp[word]dp[word] = longest chain ending at that word. For each word, check all possible predecessors (remove one char).