2
public int findLUSlength(String[] strs) {3
Arrays.sort(strs, (a, b) -> b.length() - a.length()); // sort descending order by length4
// store the frequency of all strings in array5
Map<String, Integer> map = new HashMap<>();6
for (String s : strs) map.put(s, map.getOrDefault(s, 0) + 1);8
for (int i = 0; i < strs.length; i++) {9
if (map.get(strs[i]) != 1) continue; // string is not unique11
for (j = 0; j < i; j++) {12
if (isSubsequence(strs[i], strs[j])) break;14
// if it is not a subsequence of any other larger string15
if (j == i) return strs[i].length();17
return -1; // no string satisfies the criterion20
public boolean isSubsequence(String a, String b) {22
while (i < a.length() && j < b.length()) if (a.charAt(i) == b.charAt(j++)) i++;23
return i == a.length();