filmov
tv
Google Coding Interview: Longest String Chain (Leetcode 1048)

Показать описание
Problem:
We have a list of words in lowercase letters where a word w1 is a predecessor of w2 if adding one letter from one of them makes it equal to the other one (for example w1 = ab, w2 = acb then w1 is a predecessor for w2)
Return the length of the longest chain that can be formed in the list of word such that each word is a predecessor of the next
Example 1:
words = ["a","b","c", "ab","abc","abd","abcd"]
result: 4
("a" to "ab" to "abc" to "abcd")