Longest String Chain
Problem statement
You are given an array of lowercase words words representing a dictionary.
A string chain starts with one dictionary word. At each step, remove exactly one character from the current word. The resulting word must also be present in the dictionary.
Return the maximum number of words in any valid chain. A single dictionary word forms a chain of length 1.
FastPrep practice interpretation: Repeated copies of the same word do not create extra chain positions; membership is determined by distinct word values.
Function
longestChain(words: String[]) → intExamples
Example 1
words = ["a","and","an","bear"]return = 3The chain ["and", "an", "a"] removes one character at each step and has length 3.
Example 2
words = ["a","b","ba","bca","bda","bdca"]return = 4One longest chain is ["bdca", "bda", "ba", "a"].
Example 3
words = ["abcd","dbqca"]return = 1Neither word becomes the other by deleting one character, so the longest chain contains one word.
Constraints
1 <= words.length <= 500001 <= words[i].length <= 60- Every word contains only lowercase English letters from
athroughz.
Source note: The source slide shows the HackerRank statement, example, function name, return type, and constraints.