Longest String Chain
Updated
Problem statement
You are given an array of words consisting of lowercase English letters.
A word first is a predecessor of second when inserting exactly one letter anywhere in first, without changing the order of its existing letters, produces second. For example, abc is a predecessor of abac, but cba is not a predecessor of bcaa.
A word chain is a sequence in which every word is a predecessor of the next word. A single word is a valid chain of length one.
Return the greatest possible length of a chain formed from the given words.
Function
longestStrChain(words: String[]) → intExamples
Example 1
words = ["a","b","ba","bca","bda","bdca"]return = 4One longest chain is ["a", "ba", "bda", "bdca"], which has length 4.
Example 2
words = ["xbc","pcxbcf","xb","cxbc","pcxbc"]return = 5All five words form the chain ["xb", "xbc", "cxbc", "pcxbc", "pcxbcf"].
Example 3
words = ["abcd","dbqca"]return = 1No word is a predecessor of the other, so a single-word chain such as ["abcd"] is longest.
Constraints
1 <= words.length <= 10001 <= words[i].length <= 16- Every word contains only lowercase English letters.
More LinkedIn interview questions
- Allocate Mailboxes with Squared DistanceONSITE INTERVIEW · Seen Nov 2026
- Find Leaves of a Binary TreeONSITE INTERVIEW · Seen Nov 2026
- Max Points on a LineONSITE INTERVIEW · Seen Nov 2026
- Maximum Product of a Contiguous SubarrayPHONE SCREEN · Seen Nov 2026
- Maximum Sum of a Contiguous SubarrayPHONE SCREEN · Seen Nov 2026
- Merge Two Sorted ListsPHONE SCREEN · Seen Nov 2026
- Sqrt(x)PHONE SCREEN · Seen Nov 2026
- Total Years of Work ExperiencePHONE SCREEN · Seen Nov 2026
- Explore an Unknown Grid and Find a PathONSITE INTERVIEW · Seen Nov 2026
- Fire Station Response BillONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Longest String ChainVisa · OAVisa interview questions
- Count Equal-Frequency SubsequencesExpedia · OAExpedia interview questions
- String Formation (Also for AI/ML Software Engineer Intern :)Snowflake · OASnowflake interview questions
- Word BreakAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Word BreakMoveworks · ONSITE INTERVIEWMoveworks interview questions
- Word Break with a Reusable DictionaryMeta · ONSITE INTERVIEWMeta interview questions
- Minimum Dictionary SegmentsGoogle · PHONE SCREENGoogle interview questions
- Word BreakBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Can the Text Split Into Dictionary WordsAdobe · PHONE SCREENAdobe interview questions
- Longest Common URL History RunDatadog · PHONE SCREENDatadog interview questions