words. A subsequence of a string is obtained by deleting any of its characters (possibly none) without reordering the rest.
Call a string t private to the element words[i] if t is a subsequence of words[i] and of no other element of the array (duplicates count as separate elements).
Return the greatest length of a string that is private to at least one element, or -1 if no such string exists.words=['cat', 'act', 'ca'] → 3
The string "act" is a subsequence of the word "act" alone: neither "cat" nor "ca" yields it. Its length is 3.
words=['xyz', 'xyz', 'xy'] → -1
Everything obtainable from "xy" by deletions is also obtainable from "xyz", and the two "xyz" are identical. No word owns a subsequence of its own, so the answer is -1.
words.length ≤ 500words[i].length ≤ 10words[i] consists of lowercase English letterswords=['cat', 'act', 'ca']
3
Run checks the first 3 tests in your browser. Submit checks all 101 tests on the server, hidden ones included.