description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | import sys
q = int(sys.stdin.readline())
for Q in range(q):
n, k = map(int, sys.stdin.readline().split())
s = sys.stdin.readline()
dp = [0] * 3
if n == 1 or k == 1:
print(0)
else:
s1 = 0
for i in range(k):
if i % 3 == 0 and s[i] != "R":
s1 += 1
... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VA... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | import sys
for _ in range(int(input())):
n, k = map(int, sys.stdin.readline().split())
st = sys.stdin.readline()
dp = [[1, 1, 1] for i in range(n + 1)]
dp[0][0] = dp[0][1] = dp[0][2] = 0
for i in range(n):
if st[i] == "R":
dp[i + 1][0] = 0
elif st[i] == "G":
... | IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STR... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | import sys
input = sys.stdin.readline
a = int(input())
for i in range(a):
n, k = map(int, input().split())
dp = [[(0) for i in range(n - k + 1)] for i in range(3)]
s = input()
c1 = 0
c2 = 0
c3 = 0
for i in range(k):
if i % 3 == 0:
if s[i] == "R":
c2 += 1
... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | import sys
from itertools import accumulate
readline = sys.stdin.readline
q = int(readline())
for query in range(q):
n, k = map(int, readline().split())
s = readline()[:-1]
RGB = "RGB"
sum = [[0] * n] * 3
res = n
for i in range(3):
for j in range(n):
sum[i][j] = int(s[j] != ... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR STRING ASSIGN VAR BIN_OP LIST BIN_OP LIST NUMBER VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASS... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | T = int(input())
for t in range(T):
N, K = map(int, input().split())
s = input()
D = K
t = "RGB"
if K == 1:
D = 0
else:
for m in range(3):
d = 0
a = [0] * N
for i in range(N):
if s[i] != t[(m + i) % 3]:
a[i] ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR STRING IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR I... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | import sys
input = sys.stdin.readline
q = int(input())
rgb = "RGB"
for _ in range(q):
n, k = map(int, input().split())
s = input()
ans = n
for i in range(3):
r = [0]
l = i
for c in s:
r.append(r[-1] + (1 if c != rgb[l] else 0))
l = (l + 1) % 3
... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VA... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | t = int(input())
for _ in range(t):
n, k = map(int, input().split())
s = input()
if n == 1:
print(0)
continue
A1 = "RGB" * n
A2 = "GBR" * n
A3 = "BRG" * n
ans = k
x1 = 0
x2 = 0
x3 = 0
for j in range(0, k):
x1 += s[j] != A1[j]
x2 += s[j] != A2[j... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NU... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | a = int(input())
ot = ""
for i in range(a):
b, c = list(map(int, input().split()))
s = input()
pref = [0] * (b + 1)
pref1 = [0] * (b + 1)
pref2 = [0] * (b + 1)
n = "RGB"
n1 = "GBR"
n2 = "BRG"
for j in range(b):
pref[j + 1] = pref[j]
if s[j] != n[j % 3]:
pr... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMB... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | import sys
def main():
def diff(s, l):
ret1 = [(0) for k in range(len(s))]
for k in range(len(s)):
if k % 3 == 0 and s[k] != "R":
ret1[k] = 1
if k % 3 == 1 and s[k] != "G":
ret1[k] = 1
if k % 3 == 2 and s[k] != "B":
... | IMPORT FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR STRING ASSIGN VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR STRING ASSIGN VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR STRING ASSIGN VAR VAR NUMBER ASSIGN... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | import sys
input = sys.stdin.readline
rgb = "RGB"
for _ in range(int(input())):
n, k = map(int, input().split())
s = input().rstrip()
costs = [([0] * (n + 1)) for i in range(3)]
for i in range(3):
for j in range(n):
costs[i][j + 1] = costs[i][j] + (1 if rgb[(i + j) % 3] != s[j] else... | IMPORT ASSIGN VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | import sys
input = sys.stdin.readline
q = int(input())
for testcases in range(q):
n, k = list(map(int, input().split()))
S = list(input().strip())
for i in range(n):
if S[i] == "R":
S[i] = 0
elif S[i] == "G":
S[i] = 1
else:
S[i] = 2
ANS = 1 <<... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER ASSIGN ... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | import sys
def main():
N = int(sys.stdin.readline().strip())
for _ in range(N):
n, k = [int(x) for x in sys.stdin.readline().strip().split()]
s = sys.stdin.readline().strip()
S = "RGB"
err = [[0] for _ in S]
res = [n for i in range(len(S))]
for i, c in enumerate... | IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR LIST NUMBER VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL V... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | from sys import stdin, stdout
def check_diff(s, rgb):
n = len(s)
arr = []
for i in range(n):
if s[i] == rgb[i]:
arr.append(0)
else:
arr.append(1)
return arr
q = int(stdin.readline().rstrip())
for _ in range(q):
n, k = map(int, stdin.readline().rstrip().spl... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | temp = ""
for _ in range(int(input())):
n, k = map(int, input().split())
s = input()
r = "RGB" * (n // 3) + "RGB"[: n % 3]
g = "GBR" * (n // 3) + "GBR"[: n % 3]
b = "BRG" * (n // 3) + "BRG"[: n % 3]
ra = []
ga = []
ba = []
for i in range(n):
if r[i] == s[i]:
ra.ap... | ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BI... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | import sys
t = int(sys.stdin.readline())
for _ in range(t):
n, m = map(int, sys.stdin.readline().split())
a = sys.stdin.readline()
b = 1
c = [0] * 3
a1 = "RGB" * (n // 3 + 1)
a1 = a1[:n]
a2 = "GBR" * (n // 3 + 1)
a2 = a2[:n]
a3 = "BRG" * (n // 3 + 1)
a3 = a3[:n]
c1 = c2 = c3... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP STRING BIN_OP BIN... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | from sys import stdin
input = stdin.readline
for _ in range(int(input())):
n, k = map(int, input().split())
l = input()
s = "RGB"
minim = k
for j in range(3):
d = [0] * (n + 1)
for i in range(n):
d[i + 1] = d[i] if s[(i + j) % 3] == l[i] else d[i] + 1
if i >=... | ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | from sys import stdin
input = stdin.readline
test = "RGB"
for i in range(int(input())):
a, m = map(int, input().split())
s = input()
f = 100000000
ans = [([0] * a) for i in range(3)]
for i in range(3):
for j in range(a):
ans[i][j] += s[j] != test[(i + j) % 3]
for i in range(... | ASSIGN VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | import sys
input = sys.stdin.readline
for _ in range(int(input().strip())):
n, k = list(map(int, input().strip().split()))
inp = input().strip()
st = "RGB"
ans = float("inf")
for offset in range(3):
cur = 0
pre = []
for i in range(n):
if inp[i] != st[(i + offset)... | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR F... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | def RGBstring(s, n, k):
if n == 1:
return 0
string = "RGB" * n
s1 = string[0:n]
s2 = string[1 : n + 1]
s3 = string[2 : n + 2]
arr1, arr2, arr3 = [], [], []
for i in range(n):
if s[i] != s1[i]:
arr1.append(1)
else:
arr1.append(0)
if s[i]... | FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR LIST LIST LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR VA... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | import sys
input = sys.stdin.readline
I = lambda: list(map(int, input().split()))
(t,) = I()
for _ in range(t):
n, k = I()
s = input()
an = k
rq = "RGB"
for j in range(3):
cr = 0
for i in range(k):
if s[i] != rq[(j + i) % 3]:
cr += 1
an = min(cr, ... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_O... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | import sys
input = sys.stdin.readline
q = int(input())
d = {"R": 0, "G": 1, "B": 2}
for _ in range(q):
n, k = map(int, input().split())
s = list(input().rstrip())
for i in range(n):
s[i] = d[s[i]]
t = [((s[i] - i) % 3) for i in range(n)]
cnt = [0] * 3
for i in range(k):
cnt[t[i]... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR BIN_O... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | from sys import stdin
input = stdin.readline
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
s = [i for i in input().strip()]
if k == 1:
print(0)
else:
seq = ["R", "G", "B"]
dp = [([0] * n) for i in range(3)]
dp[0][0] = int(s[0] != "R")
dp[1]... | ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSI... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | from sys import stdin
input = stdin.readline
for _ in range(int(input())):
n, k = map(int, input().split(" "))
s = input()
c1 = c2 = c3 = 0
s1 = "RGB"
s2 = "GBR"
s3 = "BRG"
ans = n
for i in range(k):
if s[i] != s1[i % 3]:
c1 += 1
if s[i] != s2[i % 3]:
... | ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER I... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | queries = int(input())
rgb = ["R", "G", "B"]
r_idx, g_idx, b_idx = 0, 1, 2
ret = ""
for q in range(queries):
n, k = list(map(int, input().split()))
s = input()
if n == 1 or k == 1:
ret += "0\n"
continue
num_windows = n - k + 1
r_arr = [0] * num_windows
g_arr = [0] * num_windows
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | x = int(input())
y = []
def kukareku(st, k):
ans0 = 0
ans1 = 0
ans2 = 0
a = 1
sp = []
spans = []
for i in range(0, len(st)):
f = []
if i % 3 == 0:
if st[i] == "R":
f = [0, 1, 1]
elif st[i] == "G":
f = [1, 0, 1]
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST IF BIN_OP VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR LIST NUMBER NUMBER NUMBER IF VAR... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | def int_list():
return [int(c) for c in input().split()]
def int1():
return int(input())
def str_list():
return [c for c in input().split()]
def str1():
return input()
s1 = ("RGB" * 66667)[:-1]
s2 = ("GBR" * 66667)[:-1]
s3 = ("BRG" * 66667)[:-1]
q = int1()
res = []
for j in range(q):
n, k = ... | FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR ASSIGN VAR BIN_OP STRING NUMBER NUMBER ASSIGN VAR BIN_OP STRING NUMBER NUMBER ASSIGN VAR BIN_OP STRING NUMBER NUMBER ASSIGN VAR FUNC_CAL... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | import sys
input = sys.stdin.readline
def solve(s, temp, n, k):
l = list()
l.append(0)
for i in range(n):
if temp[i] != s[i]:
l.append(l[i] + 1)
else:
l.append(l[i])
mini = 1000000
for i in range(0, n - k + 1):
if l[i + k] - l[i] < mini:
... | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN V... |
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there ... | from sys import stdin, stdout
riga = stdin.readline()
query = int(riga)
for i in range(query):
riga = stdin.readline()
test = riga.split()
n = int(test[0])
k = int(test[1])
check = [["R", "G", "B"], ["G", "B", "R"], ["B", "R", "G"]]
dp = [[], [], []]
sol = [0, 0, 0]
for i in range(n):
... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST LIST STRING STRING STRING LIST STRING STRING STRING LIST STRING STRING STRING ASSIGN VAR LIST LIST LIS... |
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 _ in range(len(words) + 1)]
dp[0] = 0
words = sorted(words, key=lambda x: len(x))
hmap = collections.defaultdict(list)
for i, word in enumerate(words):
hmap[len(word)] += [(word, i)... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBE... |
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))
print(words)
def valid(word1, word2):
i = 0
j = 0
flag = False
while i < len(word1) and... | CLASS_DEF FUNC_DEF VAR VAR IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR 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 IF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR NUM... |
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))
total = len(words)
count = [(1) for _ in range(total)]
for i in range(1, total):
for j in range(i):
if self.predecessor(words[j], words[i]) and... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER RETURN 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:
if not words:
return 0
words.sort(key=len)
def isNeighbor(a, b):
if len(a) + 1 != len(b):
return False
if a == b[1:] or a == b[:-1]:
return True
... | CLASS_DEF FUNC_DEF VAR VAR IF VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR RETURN NUMBER IF VAR VAR NUMBER VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP 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:
def dfs(str):
dep = 1
for longer_str in words:
if len(longer_str) == len(str) + 1:
for i in range(len(str) + 1):
new_str = longer_str[:i] + longer_str[i +... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR 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 longestStrChain(self, words: List[str]) -> int:
words = sorted(words, key=lambda w: len(w))
dp = [None] * len(words)
dp[0] = 1
for i in range(1, len(words)):
maxi = 1
for j in list(range(0, i))[::-1]:
if self.check(words[j]... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR 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 NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER 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))
wordLevels = {}
for word in words:
if len(word) in wordLevels:
wordLevels[len(word)].append(word)
else:
wordLevels[len(word)] = [word]... | CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR 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 ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR 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 longestStrChain(self, words: List[str]) -> int:
hashtable = {}
record = [(1) for i in range(17)]
for w in words:
if len(w) not in hashtable:
hashtable[len(w)] = [{w: 1}]
else:
hashtable[len(w)].append({w: 1})
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR LIST DICT VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR DICT VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER 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 isPred(w1, w2):
if len(w1) + 1 != len(w2):
return False
flag = 0
for i in range(len(w1)):
if w1[i] != w2[i + flag] and flag == 0:
flag = 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 FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR RETURN NUMBER IF VAR VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN 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 longestStrChain(self, words: List[str]) -> int:
words.sort(key=lambda word: len(word))
lengths = [1] * len(words)
for i in range(len(words)):
for j in range(i):
if self.checkifSuccessor(words[j], words[i]):
lengths[i] = max... | CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER 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 RETURN FUNC_CALL VAR VAR VAR FUNC_DEF IF BIN_OP 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:
dicti = collections.defaultdict(set)
for word in words:
dicti[len(word)].add(word)
chars = [chr(i) for i in range(ord("a"), ord("z") + 1)]
memo = {}
def dist(word):
if word in memo:
... | 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 VAR VAR FUNC_CALL VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR STRING NUMBER ASSIGN VAR DICT FUNC_DEF IF VAR VAR RETURN VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR NUM... |
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 helper(word_pre, word_cur):
if len(word_pre) - len(word_cur) != -1:
return False
count, pre, cur = 0, 0, 0
while pre <= len(word_pre) and cur < len(word_cur):
if pre ... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIS... |
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 pred(a, b):
if len(a) == len(b) or len(a) - len(b) > 1:
return False
diff = 0
i = 0
j = 0
while i < len(a):
if a[i] == b[j]:
... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR 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 IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER VAR NUMBER RETURN 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 can_convert(self, word1, word2):
for missing_idx in range(len(word2)):
if word2[:missing_idx] + word2[missing_idx + 1 :] == word1:
return True
return False
def longestStrChain(self, words: List[str]) -> int:
words_by_length = collections.... | CLASS_DEF 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 FUNC_DEF 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 ASSIGN VAR BIN_OP LIST NUMBER 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:
explored = set()
stack = [(word, 1) for word in sorted(words, key=len, reverse=True)]
words = set(words)
best = 1
while stack:
word, chain_length = stack.pop()
best = max(best, chain_... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR STRING VAR FUNC_CALL VAR BIN_OP FUNC_CALL 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:
word_map = collections.defaultdict(int)
word_list = collections.defaultdict(list)
ans = 1
for word in words:
length = len(word)
word_list[length].append(word)
word_map[word] = 1
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR FOR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR FOR VAR VAR VAR IF 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:
n = len(words)
lis = [(1) for _ in range(n)]
def cmp(w1, w2):
for k in range(len(w1)):
if w1[0:k] + w1[k + 1 :] == w2:
return True
return False
words = s... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL 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 ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR 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:
if len(words) == 0:
return 0
def isRelate(small: str, big: str) -> bool:
for i in range(len(big)):
if small == big[:i] + big[i + 1 :]:
return True
return Fals... | CLASS_DEF FUNC_DEF VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER FUNC_DEF 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 VAR FUNC_DEF VAR IF VAR NUMBER RETURN LIST ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR RET... |
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_pred(self, word1: str, word2: str) -> bool:
if not len(word1) == len(word2) - 1:
return False
for c in word1:
if c not in word2:
return False
return True
def longestStrChain(self, words: List[str]) -> int:
words.so... | CLASS_DEF FUNC_DEF VAR VAR IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN NUMBER FOR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER VAR FUNC_DEF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR 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 match(self, small, big):
mismatch = 0
i = 0
while i < len(small):
j = i + mismatch
if small[i] == big[j]:
i += 1
continue
elif not mismatch:
mismatch = 1
elif mismatch == 1:
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR ASSIGN VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR 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:
if len(words) == 0:
return 0
def findDistance(shorterString, longerString):
if len(longerString) - len(shorterString) != 1:
return False
i, j = 0, 0
edits = 0
... | CLASS_DEF FUNC_DEF VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER VAR NUMBER 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:
length2words = defaultdict(list)
for w in words:
length2words[len(w)].append(w)
word2chain = dict()
for l in sorted(length2words):
for w in length2words[l]:
word2chain[w] = 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 FOR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR ASSIGN VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR FOR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR VAR 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:
def isPredecessor(a, b):
if len(a) != len(b) - 1 or len(b) == 1:
return False
for i in range(len(b)):
tmp = b[:i] + b[i + 1 :]
if a == tmp:
return... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL 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 RETURN NUMBER RETURN NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST 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:
def is_seq(word1, word2):
if len(word2) != len(word1) + 1:
return False
L = len(word2)
for idx in range(L):
if word1 == word2[:idx] + word2[idx + 1 :]:
... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR 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 ASSIGN VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR 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:
words.sort(key=lambda w: len(w))
def predecessor(a: str, b: str):
if len(b) - len(a) == 1:
mismatch = 0
a_idx, b_idx = 0, 0
while a_idx < len(a) and mismatch <= 1:
... | CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER I... |
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)
if not words:
return 0
max_chain_dp = {}
max_len = 1
for i in range(len(words)):
word_len = len(words[i])
max_chain_d... | CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR RETURN NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF 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 isPredecessor(s1, s2):
add = False
s1_inx = 0
s2_inx = 0
while s1_inx < len(s1) and s2_inx < len(s2):
if s1[s1_inx] == s2[s2_inx]:
s1_inx += 1
... | CLASS_DEF FUNC_DEF VAR VAR 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 IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIS... |
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 longer_by_one(self, word1, word2):
if len(word2) - len(word1) != 1:
return False
j = 0
count = 0
for i in range(len(word2)):
if i < len(word2) and j < len(word1) and word2[i] != word1[j]:
count += 1
if count... | CLASS_DEF FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER 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 longestStrChain(self, words: List[str]) -> int:
d = {j: (1) for j in words}
n = len(words)
used = {}
c = [0]
words = sorted(words, key=len)
def dfs(s, l):
if not s or s not in d:
c[0] = max(c[0], len(l))
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR RETURN ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CAL... |
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 x: len(x))
pred = [1] * len(words)
def diff1(w1, w2):
for i in range(len(w2)):
if w2[:i] + w2[i + 1 :] == w1:
return True
return ... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR 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 FUNC_DEF ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR 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)
dp = [(1) for i in range(len(words))]
for r in range(1, len(words)):
for l in range(r):
if len(words[r]) == len(words[l]) + 1:
missingLetters = i = 0
... | CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL... |
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 is_predecessor(word1: str, word2: str) -> bool:
if len(word1) + 1 == len(word2):
diffCount = 0
i, j = 0, 0
while i < len(word1) and j < len(word2):
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR 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 NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER RETURN 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.sort(key=len)
print(words)
solutions = []
numWords = len(words)
for i in range(numWords):
self.getSequences(
words[i + 1 :], len(words[i]) + 1, [words[i]], words[i], solutio... | CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER LIST VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR 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:
if not words:
return 0
words.sort(key=lambda x: len(x))
n = len(words)
dp = [(1) for i in range(n)]
for i in range(1, n):
for j in range(i):
if self.is_predecessor(wor... | CLASS_DEF FUNC_DEF VAR VAR IF VAR RETURN NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER 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 RETURN FUNC_CAL... |
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 x: len(x))
dp = [1] * len(words)
res = 1
for i in range(len(words)):
for j in range(0, i):
if len(words[i]) > len(words[j]) and self.isPrecessor(
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL 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 NUMBER VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN 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:
if not words:
return 0
dp = [(1) for _ in words]
largest = 1
words.sort(key=lambda s: len(s))
print(words)
def predecessor(big_word, small_word):
b = 0
s = 0
... | CLASS_DEF FUNC_DEF VAR VAR IF VAR RETURN NUMBER ASSIGN VAR NUMBER VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR RETURN NUMBER WHILE VAR FUNC_CALL VAR VAR 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:
words = sorted(words, key=len)
def onediff(word1, word2):
if len(word1) + 1 != len(word2):
return False
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 VAR FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL 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 longestStrChain(self, words: List[str]) -> int:
def compare(s1, s2):
if abs(len(s1) - len(s2)) != 1:
return False
if len(s2) > len(s1):
s1, s2 = s2, s1
broke = False
s1, s2 = list(s1), list(s2)
... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR 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:
def dfs(cur):
if cur not in s:
return 0
if len(cur) == 0:
return 0
if cur in d:
return d[cur]
res = 1
for i in range(len(cur)):
... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER 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 ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR VAR RETUR... |
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))
N = len(words)
self.longest = [None] * N
max_len = 1
for i in range(N):
max_len = max(max_len, self.__findLongestAfter(words, i))
return max_len
def ... | CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN NUMBER FOR 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:
def f(x, y):
if len(x) != len(y) - 1:
return False
p = len(x)
for i in range(len(x)):
if x[i] != y[i]:
p = i
break
for... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER EXPR 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:
def is_predecessor(w1, w2):
for i in range(len(w1)):
if w1[i] != w2[i]:
return w1[i:] == w2[i + 1 :]
return True
words.sort(key=len, reverse=True)
len_words = le... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR 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 NUMBER VAR IF BIN_OP 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:
words.sort(key=len)
if not words:
return 0
n = len(words)
dp = [1] * n
for i in range(n):
for j in range(i):
if self.valid(words[j], words[i]):
dp[... | CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR RETURN 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 VAR IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER RETURN FUNC_CALL VAR VAR VAR FUNC_DEF IF 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 string1(self, s1, s2):
if abs(len(s1) - len(s2)) > 1 or abs(len(s1) - len(s2)) == 0:
return False
i = 0
j = 0
k = 0
while i < len(s1) and j < len(s2):
if k > 1:
return False
if s1[i] != s2[j]:
... | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER 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 NUMBER RETURN NUMBER IF 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:
words = sorted(words, key=lambda x: len(x))
DP = [(0) for i in words]
max_len = 0
for i in range(len(words)):
length = []
for j in range(1, i + 1):
if len(words[i - j]) < len(... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP... |
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 = collections.defaultdict(int)
for word in words:
dp[word] = max([dp[word[:i] + word[i + 1 :]] for i in range(len(word))]) + 1
return max(dp.values()) | CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR 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:
visited = set()
word_dict = {}
for word in words:
word_dict[word] = 1
def visit(word):
visited.add(word)
for i in range(len(word)):
child = word[:i] + word[i + 1 ... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER FUNC_DEF EXPR FUNC_CALL 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 IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP 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:
res = 0
dic = collections.defaultdict(int)
words.sort(key=lambda x: len(x))
for w in words:
m = len(w)
for i in range(m):
new = w[:i] + w[i + 1 :]
dic[w] = max... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR 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 VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR 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:
counter = collections.defaultdict(int)
longest = 0
for w in sorted(words, key=len):
for i in range(len(w)):
subword = w[:i] + w[i + 1 :]
count = counter[subword] + 1
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR 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 ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN 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 edit_dist(w1, w2):
n = len(w1)
m = len(w2)
if n + 1 != m:
return False
mismatch = 0
i = 0
j = 0
while i < n and j < m:
... | CLASS_DEF FUNC_DEF VAR VAR 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL ... |
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)
self.longest = [None] * N
max_len = 1
for i in range(N):
max_len = max(max_len, self.__findLongestAfter(words, i))
return max_len
def __isPredecess... | CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER W... |
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 word: len(word))
n = len(words)
if n == 1:
return 1
ans = 1
dp = [1] * n
def match(i, j):
idx_i = 0
idx_j = 0
skipped... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR IF VAR RETURN 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 helper(self, memo, s, w):
if w in memo:
return memo[w]
count = 0
for i in range(len(w)):
pre = w[:i] + w[i + 1 :]
if pre in s:
count = max(count, self.helper(memo, s, pre))
memo[w] = 1 + count
return 1 +... | CLASS_DEF 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 FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP NUMBER VAR RETURN BIN_OP NUMBER VAR FUNC_DEF VAR VAR ASSIGN VAR NUMBER 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 isPredecessor(self, s1, s2):
if len(s2) - len(s1) != 1:
return False
newcharfound = False
for i in range(len(s2)):
if not newcharfound:
if i == len(s1):
return True
if s1[i] != s2[i]:
... | CLASS_DEF FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF VAR VAR EXP... |
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 w: len(w))
word_chains = {w: (1) for w in words}
for word in words:
for i in range(len(word)):
sub_word = word[:i] + word[i + 1 :]
if sub_word in words:
... | CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR VAR 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 FUNC_CALL VAR BIN_OP VAR VAR 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 checkPre(self, small, large):
i = 0
j = -1
while True:
l = r = True
if i < len(small) and small[i] == large[i]:
i += 1
else:
l = False
if j + len(small) >= 0 and small[j] == large[j]:
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR RETURN BIN_OP VAR VAR FUNC_CALL VAR VAR FUNC_DEF VAR 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:
def connected(x, y):
i, j = 0, 0
count = 0
while i < len(y) and j < len(x):
if y[i] != x[j]:
if count == 0:
j += 1
cou... | CLASS_DEF FUNC_DEF VAR VAR 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 IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR 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, words: List[str]) -> int:
sort = [[] for _ in range(max(map(len, words)))]
for el in words:
sort[len(el) - 1].append(el)
d = collections.defaultdict(int)
for row in sort:
for w in row:
for i in range(l... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR 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 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):
if not words:
return 0
wordTable = self.buildWordTable(words)
maxLen = 0
visited = set()
for wordLen in range(min(wordTable), max(wordTable) + 1):
for word in wordTable[wordLen]:
if wor... | CLASS_DEF FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF 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:
dp = [0] * len(words)
words.sort(key=lambda x: len(x))
def predecessor(a, b):
if len(a) == len(b):
return False
diff = 0
i = 0
j = 0
while i < len... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR 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 VAR NUMBER IF VAR NUMBE... |
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 plusOne(self, a, b):
bigger = max([a, b], key=len)
smaller = min([a, b], key=len)
for i in range(len(bigger)):
if bigger[:i] + bigger[i + 1 :] == smaller:
return True
return False
def longestStrChain(self, words: List[str]) -> int... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR FUNC_CALL VAR LIST VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN NUMBER RETURN NUMBER FUNC_DEF VAR VAR ASSIGN VAR DICT ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL... |
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 get_dict(self, word):
d = {}
for c in word:
d[c] = d.get(c, 0) + 1
return d
def is_close(self, word1, word2):
dict_word1 = self.get_dict(word1)
dict_word2 = self.get_dict(word2)
diff = False
for letter, freq in list(dict_w... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER IF VAR ASSIGN 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 longestStrChain(self, words: List[str]) -> int:
sets = collections.defaultdict(set)
n, dp = 0, {}
for word in words:
n = max(n, len(word))
sets[len(word)].add(word)
dp[word] = 1
ans = 1
for i in reversed(list(range(2, n... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER DICT FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER 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:
chains = {}
len_arr = [len(x) for x in words]
min_len, max_len = min(len_arr), max(len_arr)
max_len_w = [w for w in words if len(w) == max_len]
for w in max_len_w:
chains[w] = 1
for lengt... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR 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)
if N < 2:
return N
words.sort(key=len)
Table = {word: (1) for word in words}
result = 1
for word in words:
for j in range(len(word)):
subword = ... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN VAR EXPR 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 VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER 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 = set(words)
dp = {}
def chainEndingAt(word):
if word not in words:
return 0
if word not in dp:
chain_len = 1
for i in range(len(word)):
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FUNC_DEF IF VAR VAR RETURN NUMBER IF 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 ASSIGN VAR VAR VAR RETURN VAR VAR RE... |
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:
lengthMap = {}
for word in words:
n = len(word)
if n not in lengthMap:
lengthMap[n] = []
lengthMap[n].append(word)
arr = [(0) for i in range(len(words))]
dp = {i: ... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR 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 issubsequence(self, str1, str2):
str1_pointer = 0
for i in range(len(str2)):
if str2[i] == str1[str1_pointer]:
str1_pointer += 1
if str1_pointer == len(str1):
return True
return False
def longestStrChain(self, ... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF VAR VAR ASSIGN VAR DICT FOR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR LIST VAR EXPR FUNC_CALL VAR FUNC_CALL 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:
n = len(words)
lis = defaultdict(int)
words = sorted(words, key=len)
print(words)
ans = 0
for i in range(n):
w = words[i]
for j in range(len(words[i])):
s = w[... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR 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 longestStrChain(self, words: List[str]) -> int:
li = {word: (1) for word in words}
words.sort(key=len)
ans = 1
for word in words:
for i in range(len(word)):
new = word[:i] + word[i + 1 :]
if new in words:
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR EXPR FUNC_CALL 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 IF VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR 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:
words.sort(key=len)
word_dict = defaultdict(int)
longest = 0
for word in words:
for i in range(len(word)):
wc = word[:i] + word[i + 1 :]
word_dict[word] = max(word_dict[wc... | CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL 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 ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN 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 longest_chain(word, word_set, memo):
if word not in word_set:
return 0
if word not in memo:
longest = 1
for i in range(len(word)):
next_word =... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF 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 BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VA... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.