FastPrepFind Longest Chain

Find Longest Chain

Bloomberg LP logoBloomberg LPMediumFULLTIMEOA
Learn

Problem statement

Given a dictionary of many words:

- bac, ac, a, c, bads

For each word, each time you can delete one letter, and the resulting word must still be in the dictionary. The task is to find the longest chain that can be formed.

Function

longestChain(words: String[]) → int

Examples

Example 1

words = ["bac", "ac", "a", "c", "bads"]return = 3

The longest chain that can be formed starting with "bac" is "bac" -> "ac" -> "a", which has a length of 3.

Constraints

🍓🍓

More Bloomberg LP problems

See Bloomberg LP hiring insights
public int longestChain(String[] words) {
  // write your code here
}
words["bac", "ac", "a", "c", "bads"]
expected3
Checking account…