3
Boolean compareForIncreaseByOne(String str1, String str2) {4
// str 1 will be long than str27
if (str1.length() != (str2.length() + 1)) {10
while (first < str1.length()) {11
if (second < str2.length() && str1.charAt(first) == str2.charAt(second)) {18
if (first == str1.length() && second == str2.length()) {24
public int longestStrChain(String[] words) {26
Arrays.sort(words, (a, b) -> a.length() - b.length()); // as Sequence/Subset are not ordered27
int[] dp = new int[N];30
for (int i = 0; i < N; i++) {31
for (int j = 0; j < i; j++) {32
if (compareForIncreaseByOne(words[i], words[j]) && dp[j] + 1 > dp[i]) {34
maxi = Math.max(maxi, dp[i]);