You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* You are given an array of words where each word consists of lowercase English letters.
3
+
4
+
wordA is a predecessor of wordB if and only if we can insert exactly one letter anywhere in wordA without changing the order of the other characters to make it equal to wordB.
5
+
6
+
For example, "abc" is a predecessor of "abac", while "cba" is not a predecessor of "bcad". A word chain is a sequence of words [word1, word2, ..., wordk] with k >= 1, where word1 is a predecessor of word2, word2 is a predecessor of word3, and so on. A single word is trivially a word chain with k == 1.
7
+
8
+
Return the length of the longest possible word chain with words chosen from the given list of words.
9
+
10
+
Input Format
11
+
12
+
len = 6 arr = ["a","b","ba","bca","bda","bdca"]
13
+
14
+
Constraints
15
+
16
+
1 <= words.length <= 1000
17
+
1 <= words[i].length <= 16
18
+
words[i] only consists of lowercase English letters.
19
+
Output Format
20
+
21
+
4
22
+
23
+
Sample Input 0
24
+
25
+
6
26
+
a b ba bca bda bdca
27
+
Sample Output 0
28
+
29
+
4
30
+
Explanation 0
31
+
32
+
One of the longest word chains is ["a","ba","bda","bdca"].
33
+
Sample Input 1
34
+
35
+
5
36
+
xbc pcxbcf xb cxbc pcxbc
37
+
Sample Output 1
38
+
39
+
5
40
+
Explanation 1
41
+
42
+
All the words can be put in a word chain ["xb", "xbc", "cxbc", "pcxbc", "pcxbcf"].
43
+
44
+
Sample Input 2
45
+
46
+
2
47
+
abcd dbqca
48
+
Sample Output 2
49
+
50
+
1
51
+
Explanation 2
52
+
53
+
The trivial word chain ["abcd"] is one of the longest word chains.
54
+
["abcd","dbqca"] is not a valid word chain because the ordering of the letters is changed.
* You are given an integer array matchsticks where matchsticks[i] is the length of the ith matchstick. You want to use all the matchsticks to make one square. You should not break any stick, but you can link them up, and each matchstick must be used exactly one time. Return true if you can make this square and false otherwise.
3
+
4
+
Example 1:
5
+
6
+
Input: matchsticks = [1,1,2,2,2] Output: true Explanation: You can form a square with length 2, one side of the square came two sticks with length 1.
7
+
8
+
Example 2: Input: matchsticks = [3,3,3,3,4] Output: false Explanation: You cannot find a way to form a square with all the matchsticks.
0 commit comments