description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: n = len(words) def extraChar(s1, s2): l1, l2 = sorted(s1), sorted(s2) diff = 0 i, j = 0, 0 if len(s1) == len(s2) + 1: while i < len(s1) and j < len(s2): ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VA...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: dp = {} result = 1 for word in sorted(words, key=len): dp[word] = 1 for i in range(len(word)): prev = word[:i] + word[i + 1 :] if prev in dp: dp[wo...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR V...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: def isPred(w1, w2): i, j = 0, 0 while i < len(w1): if w1[i] != w2[j]: if j != i: return False j += 1 else: ...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VA...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: di = defaultdict(list) for w in words: di[len(w)].append(w) L, U = min(di.keys()), max(di.keys()) dp = [1] * len(di[L]) ans = 1 def ispred(w1, w2): skip = False f...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHI...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: dp = {} words_dict = {} for word in words: dp[word] = -1 if words_dict.get(len(word)): words_dict[len(word)].append(word) else: words_dict[len(word)] = [wo...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR LIST VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR FUNC_DEF IF V...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: words.sort(key=len) dp = [(1) for _ in words] for start in range(len(words)): for end in range(start - 1, -1, -1): if len(words[end]) < len(words[start]) - 1: break ...
CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR V...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def checkPredecessor(self, word_1, word_2): find_extra = False for i in range(len(word_1)): chr_1 = word_1[i] if not find_extra: chr_2 = word_2[i] else: chr_2 = word_2[i + 1] if chr_1 != chr_2: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR IF VAR RETURN NUMBER IF VAR VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER RETURN NUMBER FUNC_DEF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSI...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: def check(w1, w2): if len(w1) != len(w2) - 1: return False cnt = 0 idx1 = 0 idx2 = 0 while idx1 < len(w1) and idx2 < len(w2) and cnt <= 1: if w1[i...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def isSubString(self, s1, s2): diff = 0 l = len(s1) ll = len(s2) if ll - l != 1: return False i = 0 j = 0 diff = 0 while i < l and diff < 2: if s1[i] == s2[j]: i += 1 j += 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER FU...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: words.sort(key=len) graph = {} max_dist = 0 for word in words: length = len(word) dist = 0 for i in range(length): if (check := word[:i] + word[i + 1 :]) in graph:...
CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: def check(i, j): w1 = words[i] w2 = words[j] for k in range(len(w2)): if w1 == w2[:k] + w2[k + 1 :]: return True return False buckets = defaultdi...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR LIST VAR ASSIGN VAR FUNC_CALL VAR VAR ...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def can_move(self, a, b): b_letters = Counter(b) for char in a: b_letters[char] -= 1 if b_letters[char] < 0: return False elif b_letters[char] == 0: b_letters.pop(char) return b_letters.popitem()[1] == 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR NUMBER NUMBER FUNC_DEF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FUNC_DEF IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FU...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def predecessor(self, w1, w2): i = 0 diffs = 0 while i < len(w1): if w1[i] != w2[i]: diffs = 1 break i += 1 if diffs == 0: return True return w1 == w2[:i] + w2[i + 1 :] def longestStrCha...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: word_list = sorted(words, key=lambda x: len(x)) word_dict = {word: (1) for word in word_list} longest = 0 for word in word_list: for i in range(len(word)): test = word[:i] + word[i + 1 :]...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR VA...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: dp = collections.defaultdict(int) for w in sorted(words, key=len): for i in range(len(w)): dp[w] = max(dp[w], 1 + dp[w[:i] + w[i + 1 :]]) return max(dp.values())
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: if not words: return 0 words = sorted(words, key=len) map = {} DP = [(1) for idx in range(len(words))] for i in range(len(words)): map = {} for j in range(0, i): ...
CLASS_DEF FUNC_DEF VAR VAR IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER F...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: if len(words) == 0: return False words.sort(key=lambda x: len(x)) def check(a, b): for i in range(len(b) - 1): if a[i] != b[i]: return b[i + 1 :] == a[i:] ...
CLASS_DEF FUNC_DEF VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR RETURN VAR BIN_OP VAR NUMBER VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CA...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: words = sorted(words, key=len) n = len(words) def match(l, r): a = words[l] b = words[r] if len(a) + 1 != len(b): return False i, j = 0, 0 while i...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMB...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: n = len(words) words.sort(key=len) f = [1] * n def ispre(w1, w2): if len(w1) != len(w2) - 1: return False it = iter(w2) return all(c in it for c in w1) r...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_C...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: d = collections.defaultdict(list) for word in words: d[len(word)].append(word) lengths = sorted(list(d.keys())) self.mem = {} def dfs(word): if len(word) == lengths[-1]: ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FUNC_DEF IF FUNC_CALL VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR RETURN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: size = 0 wordSet = set(words) mem = {} def dfs(s): if s in mem: return mem[s] maxpath = 1 for i in range(len(s)): new = s[:i] + s[i + 1 :] ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FUNC_DEF IF VAR VAR RETURN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VA...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: wset = set(words) memo = {} def dp(word): if word in memo: return memo[word] ans = 1 for i in range(len(word) + 1): for j in range(26): ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FUNC_DEF IF VAR VAR RETURN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR VAR IF VAR VAR ASSIGN VAR FUN...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: l = [(1) for i in range(len(words))] words.sort(key=lambda x: len(x)) res = [[i] for i in words] for i in range(1, len(words)): for j in range(i): if len(words[j]) + 1 == len(words[i]): ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR VAR IF VAR V...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
def is_pre(s1, s2): c = 0 i = 0 for j in range(len(s2)): if i == len(s1) or s1[i] != s2[j]: c += 1 else: i += 1 return c == 1 class Solution: def longestStrChain(self, words: List[str]) -> int: words.sort(key=len) n = len(words) m = ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR NUMBER CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CA...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: n = len(words) words.sort(key=len) f = [1] * n def ispre(w1, w2): if len(w1) != len(w2) - 1: return False i = j = 0 diff = False while i < len(w1) and...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR ASSIGN VAR NUMB...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: words.sort(key=lambda x: len(x), reverse=True) minLen = len(words[-1]) dic = set(words) seen = set() self.result = 0 for word in words: if word not in seen: length = 1 ...
CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR IF F...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: words = set(words) @lru_cache() def helper(word): if not word or word not in words: return 0 return 1 + max(helper(word[:i] + word[i + 1 :]) for i in range(len(word))) retur...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR VAR RETURN NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: if not words: return 0 words = sorted(words, key=lambda x: len(x)) dp = [1] * len(words) for i in range(1, len(words)): for j in range(i - 1, -1, -1): if len(words[i]) == len(...
CLASS_DEF FUNC_DEF VAR VAR IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMB...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
def isPredecessor(src, dst): nsrc = len(src) ndst = len(dst) if nsrc + 1 != ndst: return False i = 0 while i < nsrc: if src[i] == dst[i]: i += 1 continue else: return src[i:] == dst[i + 1 :] return True class Solution: def longes...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR V...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: words.sort(key=len) print(words) def stringmatch(s1, s2): onemismatchallowed = True if len(s1) > len(s2): s2, s1 = s1, s2 if len(s1) + 1 != len(s2): retur...
CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR NUMBER A...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: if not words: return 0 words.sort(key=len) dp = [(1) for _ in range(len(words))] start = collections.defaultdict(int) end = collections.defaultdict(int) for i in range(len(words) - 1, -1,...
CLASS_DEF FUNC_DEF VAR VAR IF VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETU...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def differ(self, x1, x2): i, j = 0, 0 diff = 0 while i != len(x1) and j != len(x2): if x1[i] != x2[j]: diff += 1 else: i += 1 if diff > 1: return False j += 1 return True ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER RETURN NU...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: N = len(words) dp = [1] * N words.sort(key=len) print(words) if N == 1: return 1 def check(word1, word2): if len(word2) - len(word1) != 1: return False ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR BIN...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: def chain(w1, w2): m, n = len(w1), len(w2) if abs(m - n) != 1: return False i, j, one = 0, 0, 1 while i < m and j < n: if w1[i] == w2[j]: ...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER R...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
def find(s1, s2): i = 0 j = 0 count = 0 while i < len(s1) and j < len(s2): if s1[i] == s2[j]: i += 1 j += 1 else: j += 1 count += 1 if i == len(s1): return True if count == 1: return True return False class Sol...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUN...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: wc = {} for w in words: wc.setdefault(len(w), []) wc[len(w)].append(w) d = {} for i in sorted(wc.keys()): if i - 1 not in wc: for w in wc[i]: d...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR LIST EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR FOR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CA...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def __init__(self): self.cache = collections.defaultdict(int) def longestEndWith(self, word, words): if word in self.cache: return self.cache[word] if len(word) == 1: self.cache[word] = 1 return 1 else: for i in ra...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR RETURN VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: words = sorted(words, key=lambda w: len(w)) seenCache = {} max_len = 0 for cur_word in words: cur_len = 0 for i in range(len(cur_word)): check_word = cur_word[:i] + cur_word[i...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN ...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: def isPre(st1, st2): if len(st2) != len(st1) + 1: return False j = 0 diff = 0 for i in range(len(st2)): if diff > 1: return False ...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, wordlist: List[str]) -> int: wl = set(wordlist) def dfs(w): if len(w) == 1: return 1 if w in memo: return memo[w] l = len(w) depth = 0 for i in range(l): ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR V...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: ans, dicti, memo = ( 0, collections.defaultdict(list), collections.defaultdict(int), ) for word in words: dicti[len(word)].append(word) chars = [chr(ch) for ch in rang...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER FUNC_DEF IF VAR VAR RETURN BIN_OP VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR N...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: if not words: return 0 self.memo = {} self.ans = 1 self.words = set(words) for word in self.words: self.dfs(word) return self.ans def dfs(self, word): if len(word...
CLASS_DEF FUNC_DEF VAR VAR IF VAR RETURN NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VA...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def __init__(self): self.results = [] self.explored = dict() def traverse(self, string, listt, buffer): flag = True for i in range(len(string)): if string[:i] + string[i + 1 :] in listt: flag = False self.traverse( ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR LIST BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR EXPR FUNC_C...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: if not words: return 0 words.sort(key=lambda x: len(x)) counter = [collections.Counter(word) for word in words] dp = [1] * len(words) maxlen = 0 for i in range(len(dp)): for j...
CLASS_DEF FUNC_DEF VAR VAR IF VAR RETURN NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER FUNC_...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: dp = {} for w in sorted(words, key=len): dp[w] = max(dp.get(w[:i] + w[i + 1 :], 0) + 1 for i in range(len(w))) return max(dp.values())
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: if not words: return 0 words.sort(key=lambda x: len(x)) visited = set() res = 1 for i in range(len(words)): if words[i] in visited: continue visited.add(wo...
CLASS_DEF FUNC_DEF VAR VAR IF VAR RETURN NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR VAR FUNC_DEF IF VAR FU...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def isPredecessor(self, word1, word2): for i in range(1, len(word2) + 1): if word2[: i - 1] + word2[i:] == word1: return True return False def longestStrChain(self, words: List[str]) -> int: wordLengths = {} for word in words: ...
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF VAR VAR ASSIGN VAR DICT FOR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR LIST VAR ASSIGN VAR DICT ASS...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: def check(s, t): m, n = len(s), len(t) flag = False j = 0 if n != m + 1: return False for i in range(n): if j < m and t[i] == s[j]: ...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR ASSIGN VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VA...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: preToPost = collections.defaultdict(set) for word1 in words: for word2 in words: if self.isPredecessor(word1, word2): preToPost[word1].add(word2) ans = 0 memo = {} ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR FUNC_DEF IF VAR VAR RETURN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR ASS...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: def if_pred(a, b): if len(a) + 1 != len(b): return False i = 0 j = 0 while i < len(a): if a[i] == b[j]: i += 1 j += 1 ...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR ...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: ans = defaultdict(int) words.sort(key=len) for s in words: n = len(s) now = 0 for i in range(n): s1, s2 = s[:i], s[i + 1 :] now = max(now, ans[s1, s2]) ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: longestchain = defaultdict(int) words.sort(key=len, reverse=True) for word in words: for i in range(len(word)): pred = word[:i] + word[i + 1 :] longestchain[pred] = max(longestcha...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: def precedent(w1_c, w2_c): if len(w1_c) > len(w2_c): return False count = 0 for c in w2_c: if c in w1_c: count += w2_c[c] - w1_c[c] el...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR RETURN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL V...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: n = len(words) words = [(len(word), word) for word in words] words.sort() words = [word[1] for word in words] dp = [(1) for i in range(n)] for i in range(n): for j in reversed(list(range(...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR ...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: word_dict = {} words = [(len(w), w) for w in words] words = sorted(words) for _, w in words: word_dict[w] = 1 state_t = set() max_chain = 1 for _, word in words: chain...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR ...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def one_off(self, a, b): if abs(len(a) - len(b)) != 1: return False one_off = False i = 0 j = 0 while i < len(a) and j < len(b): if a[i] != b[j]: if one_off: return False one_off = Tr...
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR RETURN NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMB...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: cache = {} words_dict = {word: None for word in words} def chain(word): if word in cache: return cache[word] if word in words: cache[word] = 1 + max( ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT ASSIGN VAR VAR NONE VAR VAR FUNC_DEF IF VAR VAR RETURN VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR VAR RETURN NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR V...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: words.sort(key=lambda x: len(x)) counter = {} minLen = len(words[0]) maxLen = 1 for idx in range(len(words)): if len(words[idx]) == minLen: counter[idx] = 1 else: ...
CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR VA...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: dictByLen = collections.defaultdict(list) wordCounter = {} for i, w in enumerate(words): dictByLen[len(w)].append(w) wordCounter[w] = collections.Counter(w) def isOneDiff(s1, s2): ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR IF VAR NUMBER RETURN NUMBER VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR V...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: if len(words) == 0: return 0 adj = {} for w in words: for i in range(len(w)): s = w[0:i] + w[i + 1 :] if s not in adj: adj[s] = [w] ...
CLASS_DEF FUNC_DEF VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR DICT FOR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR LIST VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR DICT FUNC_DEF IF VAR ...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: _max = 0 def longestStrChain(self, words: List[str]) -> int: def dfs(cur, step): if cur not in s: return if len(cur) == 0: return self._max = max(step, self._max) for i in range(len(cur)): t...
CLASS_DEF ASSIGN VAR NUMBER FUNC_DEF VAR VAR FUNC_DEF IF VAR VAR RETURN IF FUNC_CALL VAR VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR ...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: x = lambda a: len(a) words.sort(key=x) print(words) chain_len = [None] * len(words) chain_len[0] = 1 for i in range(1, len(words)): temp = words[i] chain_len[i] = 1 ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NONE FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP V...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: dp = {} by_length = collections.defaultdict(set) for w in words: by_length[len(w)].add(w) for i, l in enumerate(sorted(by_length.keys())): if i == 0: for w in by_length[l]: ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER FOR VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER FOR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR VAR ASSIGN VAR...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: def custom_equal(word1, word2): if len(word2) == len(word1): return 0 for i in range(len(word2)): if word2[0:i] + word2[i + 1 :] == word1: return 1 re...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR RETURN NUMBER RETURN NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER FU...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: def predecessor(word1, word2): for i in range(len(word2)): if word2[0:i] + word2[i + 1 :] == word1: return True return False words.sort(key=len) words_sort = {} ...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR RETURN NUMBER RETURN NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR LIST VAR FUNC_DEF A...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: words.sort(key=lambda x: len(x)) chainLen = {w: (1) for w in words} ret = 1 for i, word1 in enumerate(words): for j in range(i + 1, len(words)): word2 = words[j] if len(wo...
CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VA...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: words_sort = [(len(word), word) for word in words] words_sort.sort() words = [word for w_len, word in words_sort] def isPredecessor(pre: str, succ: str) -> bool: if len(pre) != len(succ) - 1: ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_DEF VAR VAR IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR VAR VAR VAR N...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: wordSet = set(words) i_min = min(wordSet) @lru_cache() def aux(word): if not word or word not in wordSet: return 0 if len(word) == i_min: return 1 ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR RETURN FUNC_CALL VAR F...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: wordsListLength = len(words) if wordsListLength <= 1: return wordsListLength def isPredecessor(word1, word2): for i in range(len(word2)): if word2[:i] + word2[i + 1 :] == word1: ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN NUMBER RETURN NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR V...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: def determine(s1, s2): if len(s2) != len(s1) + 1: return False insert = False j = 0 for i in range(len(s1)): while s2[j] != s1[i]: if inse...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR IF VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN V...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: d = {w: (1) for w in words} words.sort(key=lambda x: len(x)) def check(w1, w2): if len(w1) <= len(w2): return False if len(w1) - len(w2) == 1: i = 0 j...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR ...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: self._len_to_words = collections.defaultdict(list) for w in words: self._len_to_words[len(w)].append(w) self._cache = {} self._visited = {} max_so_far = 0 for w in words: max_...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR VAR FUNC_DEF IF VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VA...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: words.sort(key=lambda x: len(x)) dp = [1] * len(words) possible_pred = [0] * len(words) for i in range(len(words) - 1, -1, -1): cur_word = words[i] cur_length = len(cur_word) for ...
CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: dp = {} table = defaultdict(list) for w in words: table[len(w)].append(w) max_len = max(len(w) for w in words) def backtracking(cur, n): if len(cur) == max_len: retur...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN NUMBER IF VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP V...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: dp = [(1) for i in range(len(words))] words.sort(key=lambda x: len(x)) for i in range(len(words)): for j in range(i): if len(words[j]) == len(words[i]): continue ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VA...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def predecessor(self, larger, smaller): largerCount = Counter(larger) for c in smaller: if c in largerCount: largerCount[c] -= 1 if largerCount[c] == 0: del largerCount[c] mc = largerCount.most_common() ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER NUMBER FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NU...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: words.sort(key=len) n = len(words) dp = [1] * n for i in range(1, n): word = words[i] word_len = len(word) for j in range(0, i): if len(words[j]) == word_len - 1: ...
CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def _check_word(self, wordlong, word2) -> bool: if len(wordlong) - len(word2) > 1 or len(wordlong) - len(word2) == 0: return False for i in range(0, len(wordlong)): newstr = wordlong[:i] + wordlong[i + 1 :] if newstr == word2: retu...
CLASS_DEF FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER VAR FUNC_DEF VAR VAR IF FUNC_CALL VAR VAR NUMBER R...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def is_chainable(self, shorter, longer): for i in range(len(longer)): if shorter == longer[:i] + longer[i + 1 :]: return True return False def longestStrChain(self, words: List[str]) -> int: sw = sorted(words, key=lambda x: len(x)) n_...
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: def dfs(w1, size): return max([dfs(w2, size + 1) for w2 in graph[w1]], default=size) graph = collections.defaultdict(list) for w in words: graph[len(w)].append(w) for w1 in words: ...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR VAR FOR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR ...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: contains = lambda w1, w2: all(l1 in w2 for l1 in w1) words.sort(key=lambda a: len(a)) n = len(words) chain = [1] * n for i in range(n): j = i + 1 while j < n and len(words[j]) == len(...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR VAR FUNC_CALL VAR ...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: by_length = collections.defaultdict(set) for word in words: by_length[len(word)].add(word) longest = 1 seen = {*()} mx = len(by_length) mn = min(by_length) for length in sorted(by...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR FOR VAR VAR VAR IF BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR LIST VAR ...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: words.sort(key=lambda x: len(x)) max_len = [1] * len(words) res = 1 for i in range(len(words) - 1): for j in range(i, len(words)): if self.isPredecessor(words[i], words[j]): ...
CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR ...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: word_graph = {} for word in words: for second_word in words: if len(second_word) == len(word) + 1: is_predecessor = True second_word_counter = Counter(second_word)...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT FOR VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: def is_predecessor(w1, w2): for i, w in enumerate(w1): if w != w2[i]: return w1[i:] == w2[i + 1 :] return True words.sort(key=len, reverse=True) len_words = len(...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR RETURN VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR ASSIGN V...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: n = len(words) for ele in words: ele = list(ele) words = sorted(words, key=lambda x: len(x)) arr = [1] * n for i in range(1, n): for j in range(0, i): if len(words[j])...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VA...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: def ispre(w1, w2): i, j = 0, 0 while i < len(w1) and j < len(w2): if w1[i] == w2[j]: i += 1 j += 1 else: j += 1 ...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR ...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: dp = {} cnt = [[] for i in range(16)] min_l = 16 for i in words: min_l = min([min_l, len(i)]) cnt[len(i) - 1].append(i) def match(a, b): i = j = 0 cnt = 0 ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR LIST VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR V...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: n = len(words) W = defaultdict(list) for i, w in enumerate(words): W[len(w)].append(i) G = defaultdict(set) for i in range(n): for j in W[len(words[i]) + 1]: found = F...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def predecessor(self, word_1, word_2): if abs(len(word_1) - len(word_2)) != 1: return False idx_1 = 0 idx_2 = 0 while idx_1 < len(word_1) and idx_2 < len(word_2): if word_1[idx_1] != word_2[idx_2]: if idx_1 != idx_2: ...
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN ...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: predecessors = dict() words = sorted(words, key=len) for i in range(len(words)): predecessors[words[i]] = [] for j in range(i): if self.isPredecessor(words[i], words[j]): ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR LIST FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER ...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: dp = [(0) for i in range(len(words))] ans = 0 words = sorted(words, key=lambda x: len(x)) for i in range(len(words)): for j in range(i): if self.prev(words[j], words[i]): ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: sorted(words, key=len, reverse=True) depth = [1] * len(words) def dfs(word): depth = 1 for i in range(len(word)): new_word = word[:i] + word[i + 1 :] if new_word in w...
CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR R...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: def is_pred(short, long): if len(short) + 1 != len(long): return False short += " " new = None for i in range(len(long)): if short[i] != long[i]: ...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR RETURN NUMBER VAR STRING ASSIGN VAR NONE FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: all_chains = [] for word in words: all_chains.extend(self.createChains(word, words)) return max(map(len, all_chains)) def createChains(self, word, words): result = [] step = [word] d...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: words.sort(key=lambda x: len(x)) print(words) n_s = len(words[0]) dic = collections.defaultdict(lambda: 0) longest_chain = 1 def search(word): if len(word) == n_s: dic[wo...
CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR B...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def isPredecessor(self, predecessorCandidate, word): if len(predecessorCandidate) != len(word) - 1: return False pWhere = 0 wWhere = 0 hasSkipped = False while pWhere < len(predecessorCandidate) and wWhere < len(word): if predecessorCa...
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR RETURN NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF VAR VAR EXPR FUN...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def IsPredecessor(self, w1, w2): if len(w1) + 1 != len(w2): return False if len(w1) == 0: return True diff = 0 for i in range(len(w2)): if i - diff == len(w1) or w1[i - diff] != w2[i]: diff += 1 return diff ...
CLASS_DEF FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER RETURN VAR NUMBER FUNC_DEF VAR VAR IF FUNC_CALL VAR VAR NUMB...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def isPredecessor(self, word1, word2): if len(word1) + 1 == len(word2): i = 0 j = 0 count = 0 while i < len(word1) and j < len(word2): if word1[i] != word2[j]: count += 1 else: ...
CLASS_DEF FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN NUMB...
Given a list of words, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac". A word chain is a sequence of words [word_1, word_2, ..., word_k] wi...
class Solution: def longestStrChain(self, words: List[str]) -> int: st = set(words) def ls(word): res = 1 for j in range(len(word)): substr = word[:j] + word[j + 1 :] if substr not in st: continue res = 1 +...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN ...