description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ... | class Solution:
def isHappy(self, n):
seen = set()
while n not in seen:
seen.add(n)
n = sum(int(i) ** 2 for i in str(n))
return n == 1
def nextHappy(self, N):
N += 1
while not self.isHappy(N):
N += 1
return N | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR RETURN VAR NUMBER FUNC_DEF VAR NUMBER WHILE FUNC_CALL VAR VAR VAR NUMBER RETURN VAR |
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ... | def happy(n):
temp = sum([pow(int(x), 2) for x in str(n)])
d = {}
d[temp] = 1
if temp == 1:
return True
while True:
temp = sum([pow(int(x), 2) for x in str(temp)])
if d.get(temp) == None:
d[temp] = 1
else:
return False
if temp == 1:
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR NUMBER RETURN NUMBE... |
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ... | class Solution:
def nextHappy(self, N):
def ha(n, l):
l.append(n)
if n == 1:
return True
s = 0
while n:
t = n % 10
s += t * t
n = int(n / 10)
if s in l:
return False
... | CLASS_DEF FUNC_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR RETURN NUMBER RETURN FUNC_CALL VAR VAR VAR VAR NUMBER WHILE NUMBER ASSIGN VAR LIST IF FUNC_CALL VAR VAR VAR RET... |
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ... | class Solution:
def nextHappy(self, N):
hno = 0
while hno != 1:
N = N + 1
l = list(str(N))
hno = 0
while hno >= 10 or hno == 0:
sum1 = 0
for i in l:
sum1 = sum1 + int(i) ** 2
hno = su... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN... |
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ... | class Solution:
def nextHappy(self, N):
memo = {}
d = {}
for i in range(10):
d[i] = i * i
def sol(cur, d):
if cur == 1:
return True
temp = 0
memo[cur] = False
for i in str(cur):
temp += d[in... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR RETURN FUNC_CALL VAR VAR VAR RETURN VAR VAR WHILE NUMBER VAR NUMBER IF... |
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ... | class Solution:
def nextHappy(self, N):
def ishappy(n):
temp = n
a = 0
while temp:
r = temp % 10
temp = temp // 10
a += r * r
if a > 9:
return ishappy(a)
if a == 1:
r... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR IF VAR NUMBER RETURN FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR IF FUNC_CALL VAR VAR RETURN VAR VAR NUMBER |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
... | def main():
s = input()
k = int(input())
s += "?" * k
N = len(s)
result = 0
for l in range(1, N):
count = 0
for i in range(N - l):
if s[i] == s[i + l] or s[i + l] == "?":
count += 1
if count == l:
result = l
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR V... |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
... | s = input() + "X" * int(input())
for v in range(len(s) - len(s) % 2, 0, -2):
for i in range(len(s) - v + 1):
if all(s[j + v // 2] in ("X", s[j]) for j in range(i, i + v // 2)):
print(v), exit() | ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER STRING VAR VAR VAR FUNC_CALL VAR VAR B... |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
... | s = input()
n = int(input())
def is_tandem(string, half):
if len(string) <= half:
return True
second = string[half:]
first = string[0 : len(second)]
return first == second
min_len = 0
if n >= len(s):
min_len = (len(s) + n) // 2 * 2
for i in range(n, len(s) + 1, 2):
total_len = i + n
... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR RETURN VAR VAR ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR V... |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
... | def tandemRepeat(i, j):
a = s[i : i + j - 1]
b = s[i - j : i - 1]
for k in range(len(a)):
if a[k] == b[k] or a[k] == "*" or b[k] == "*":
continue
else:
return False
return True
s = input()
n = int(input())
s = s + "*" * n
ans = -1
for i in range(len(s)):
for... | FUNC_DEF ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR STRING VAR VAR STRING RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP STRIN... |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
... | s = input()
k = int(input())
m = len(s) + k
ans = 0
if k >= len(s):
ans = m - m % 2
for x in range(len(s) // 2 + 1, 0, -1):
for y in range(len(s) - 2 * x):
if s[y : y + x] == s[y + x : y + 2 * x]:
ans = max(ans, 2 * x)
for l in range(m // 2, 0, -1):
c = s[m - 2 * l : m - l]
if c[: l ... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_... |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
... | s = input()
n = len(s)
k = int(input())
best = 0
if k >= n:
best = (k + n) // 2 * 2
for st in range(n):
for ln in range(2, n - st):
if s[st : st + ln // 2] == s[st + ln // 2 : st + ln]:
best = max(best, ln)
for st1 in range(n):
if (n + k - st1) % 2 == 0:
lens = (n + k - st1) // 2... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER B... |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
... | def tandem(s):
n = len(s) // 2
for i in range(n):
if s[i] != s[i + n] and s[i] != "#" and s[i + n] != "#":
return False
return True
def main():
s = input()
k = int(input())
s = s + "#" * k
n = len(s)
ans = 0
for i in range(n):
for j in range(i + 2, n + 1... | FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR VAR STRING VAR BIN_OP VAR VAR STRING RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR VAR A... |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
... | import sys
str = input()
k = int(input())
ans = 0
if k >= len(str):
print((k + len(str)) // 2 * 2)
return
for i in range(len(str)):
for j in range(0, i + 1):
len1 = len(str[j : i + 1])
len2 = len(str[i + 1 :])
minn = min(len1, len2)
if str[j : j + minn] == str[i + 1 : i + 1 ... | IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN... |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
... | from sys import stdin, stdout
nmbr = lambda: int(stdin.readline())
lst = lambda: list(map(int, stdin.readline().split()))
def fn(l):
for i in range(n - l + 1):
f = 1
for j in range(i, i + l // 2):
if a[j] == a[j + l // 2] or a[j + l // 2] == " ":
continue
f... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER STRI... |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
... | t, k = input(), int(input())
n = len(t)
s = min(k, (n + k) // 2)
for i in range(n - k):
for j in range(i + s + 1, min(n, (n + i + k) // 2 + 1)):
d = j - i
if n - j > d:
if t[i:j] == t[j : j + d]:
s = d
elif t[i : n - d] == t[j:n]:
s = d
print(2 * s) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_O... |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
... | s = input()
k = int(input())
n = len(s)
ans = min(2 * k, 2 * n)
start = min(k + 1, n + 1)
end = (n + k) // 2 + 1
for i in range(start, end):
flag = True
for j in range(n - 1, max(-1, n - (i - k) - 1), -1):
if s[j] != s[j - i]:
flag = False
break
if flag:
ans = 2 * i
f... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR... |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
... | s = input()
k = int(input())
s += "?" * k
n = len(s)
res = 0
for i in range(n):
for j in range(i + 1, n):
d = j - i + 1
if d % 2 != 0:
continue
valid = True
for e in range(i, j + 1):
if e + d // 2 > j:
break
if s[e] == "?" or s[e + ... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_O... |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
... | s = input().rstrip()
k = int(input())
if k > len(s):
print(len(s) + k - ((len(s) + k) % 2 == 1))
else:
aux = []
for j in range(1, len(s)):
i = len(s) - 1
cnt = 0
while i - j >= 0 and s[i] == s[i - j]:
i -= 1
cnt += 1
if cnt == j:
br... | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR... |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
... | s = [*input()]
k = int(input())
s.extend(["?"] * k)
m = 0
for i in range(1, len(s) // 2 + 1):
for j in range(len(s) - 2 * i + 1):
q = 0
for k in range(i):
if s[j + k] == "?" or s[j + k + i] == "?":
continue
if s[j + k] != s[j + k + i]:
q = 1
... | ASSIGN VAR LIST FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL V... |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
... | s = input()
k = int(input())
le = len(s) + k
m = 0
for i in range(len(s)):
j = 1
while i + 2 * j <= le:
mi = i + j
la = i + 2 * j
if mi >= len(s):
m = max(m, j)
if la <= len(s) and s[i:mi] == s[mi:la]:
m = max(m, j)
if mi < len(s):
xl =... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR... |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
... | def solve():
str1 = input()
num = int(input())
str2 = str1 + "0" * num
ans = num / 2
length = len(str2)
for i in range(length):
for j in range(2, length + 1, 2):
if i + j <= length:
lstr = str2[i : i + j // 2]
rstr = str2[i + j // 2 : i + j]
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER... |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
... | s = input()
k = int(input())
ans = 0
def get_max_tandem_repeat(s, n):
while n > 0:
for i in range(len(s) - 2):
if i + 2 * n > len(s):
n -= 1
break
flag = True
for j in range(i, i + n):
if s[j] != s[j + n] and s[j + n] != "... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF WHILE VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR BIN_... |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
... | def match(str1, str2):
for t in range(len(str1)):
if str1[t] != str2[t] and str2[t] != "_":
return False
return True
string = input()
k = int(input())
length = len(string)
mark = False
if k >= length:
print(2 * int((length + k) / 2))
else:
s = string + k * "_"
n = int(len(s) / ... | FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR STRING RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR ... |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
... | def tandem(n, a, i):
for k in range(i, i + n):
if a[k] != a[k + n] and a[k + n] != "??":
return 0
return 1
s = list(input().strip())
k = int(input())
s += ["??" for i in range(k)]
res = 0
for i in range(len(s)):
for n in range(1, (len(s) - i) // 2 + 1):
if tandem(n, s, i):
... | FUNC_DEF FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR STRING RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR... |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
... | def solve():
s = input()
k = int(input())
len_s = len(s)
len_f = len_s + k
max_n = int(len_f / 2)
for i in range(max_n, 0, -1):
for j in range(len_f):
if len_f - j >= 2 * i:
ok = True
for k in range(j, j + i):
if k + i < len... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN... |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
... | def tandem(s, start, l, max_len, n):
if start >= n:
if max_len - start >= 2 * l:
return True
return False
if max_len - start < 2 * l:
return False
for i in range(start, start + l):
si = s[start]
if i + l > max_len:
return False
if i + l... | FUNC_DEF IF VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR RETURN NUMBER RETURN NUMBER IF BIN_OP VAR VAR BIN_OP NUMBER VAR RETURN NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR RETURN NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR RETURN NUMBER RETURN NUMBER... |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
... | s, r = input(), int(input())
def compare(a, b):
return a[: len(b)] == b
def f(s, n, N):
if not s or n < 2 * N:
return N
for i in range(n // 2, 0, -1):
if compare(s[:i], s[i : 2 * i]):
return f(s[1:], n - 1, max(i, N))
return f(s[1:], n - 1, N)
if len(s) < r:
print((... | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN VAR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR VAR BIN_OP NUMBER VAR RETURN VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR BIN_OP NUMBER VAR RETURN FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR... |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
... | s = input()
k = int(input())
n = len(s)
if k >= n:
print(int(2 * ((n + k) // 2)))
raise SystemExit
ll = 0
for i in range(k + 1):
for l in range((n + i) // 2, i - 1, -1):
if s[n - (l - i) : n] == s[n + i - 2 * l : n - l]:
if l > ll:
ll = l
break
j = ll
while 2 ... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER IF... |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
... | def max_len(s):
N = len(s)
for L in range(N // 2, 0, -1):
for i in range(N - 2 * L + 1):
if all(
ch2 in ch1 + "_" for ch1, ch2 in zip(s[i : i + L], s[i + L : i + 2 * L])
):
return 2 * L
print(max_len(input() + "_" * int(input()))) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR STRING VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP NUMBER VAR RETURN BIN_OP NUMBER VAR EXPR F... |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
... | st = input()
num = int(input())
maxlen = 0
for start in range(len(st) + num):
for end in range(start + 1, len(st) + num, 2):
middle = (end + start + 1) // 2
ans = True
for it in range(min(len(st) - middle, end - middle)):
if st[start + it] != st[middle + it]:
ans ... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN... |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
... | s = input()
k = int(input())
ans = 0
for l in range(1, (len(s) + k) // 2 + 1):
cur = s + "a" * k
cur = "".join(
cur[i] if i < max(l, len(s)) else cur[i - l] for i in range(len(s) + k)
)
check = "".join("01"[cur[i] == cur[i + l]] for i in range(len(s) + k - l))
if "1" * l in check:
an... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL STRING VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR... |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
... | def equal(x, y):
for i in range(len(x)):
if x[i] != y[i] and "?" not in x[i] + y[i]:
return False
return True
s = input()
r = 1
for i in range(len(s) - 1):
j = (len(s) - i) // 2
while j >= 0:
if s[i : i + j] == s[i + j : i + 2 * j]:
r = max(r, j)
bre... | FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR STRING BIN_OP VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER WHILE VAR NUMBER IF VAR VAR BIN_OP VAR VAR ... |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
... | s = input()
k = int(input())
s = s + "?" * k
for i in range(len(s) // 2 + 1):
a = [0] * len(s)
for j in range(len(s) - i):
if s[j] == s[j + i] or s[j + i] == "?":
a[j] = 1
c = 0
mx = 0
for j in a:
if j == 1:
c += 1
else:
mx = max(mx, c)
... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP STRING VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ... |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
... | s = str(input())
k = int(input())
a = 0
def tandem(string):
if len(string) % 2 == 1:
return False
elif string[: len(string) // 2] == string[len(string) // 2 :]:
return True
else:
return False
if len(s) <= k:
a = 2 * ((len(s) + k) // 2)
else:
a = 2 * k
for i in range(0, le... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP... |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
... | a = input()
b = int(input())
j = 0
l = 0
for start in range(len(a) + b):
for end in range(start + 1, len(a) + b):
if (end - start + 1) % 2 == 0:
middle = (start + end) // 2 + 1
k = 0
for traverse in range(start, len(a)):
if k + middle >= len(a) or k + midd... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER ... |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
... | import sys
def readln():
return tuple(map(int, input().split()))
s = input()
(k,) = readln()
s += "?" * k
ans = len(s) // 2 * 2
while ans:
for i in range(len(s) - ans + 1):
flag = True
for j in range(i, i + ans // 2):
flag = flag and (s[j] == s[j + ans // 2] or s[j + ans // 2] ==... | IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER WHILE VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL V... |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
... | import sys
3
s = sys.stdin.readline().strip()
k = int(sys.stdin.readline())
s += "*" * k
def is_tandem(s):
n = len(s) // 2
a, b = s[:n], s[n:]
for i in range(n):
if a[i] == "*" or b[i] == "*":
continue
if a[i] != b[i]:
return False
return True
l = 0
for i in ... | IMPORT EXPR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP STRING VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBE... |
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
... | def equal(a, b):
for i in range(len(a)):
if a[i] != b[i] and a[i] != "*" and b[i] != "*":
return False
return True
string, k, best = input().strip(), int(input()), 0
string += "*" * k
for i in range(len(string) + 1):
for j in range(i + 1, len(string) + 1):
if not (j - i) % 2:
... | FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR STRING VAR VAR STRING RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR BIN_OP STRING VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ... |
An integer has sequential digits if and only if each digit in the number is one more than the previous digit.
Return a sorted list of all the integers in the range [low, high] inclusive that have sequential digits.
Example 1:
Input: low = 100, high = 300
Output: [123,234]
Example 2:
Input: low = 1000, high = 13000
Ou... | class Solution:
def sequentialDigits(self, low: int, high: int) -> List[int]:
res = []
def dfs(curr_num):
if curr_num >= low and curr_num <= high:
res.append(curr_num)
elif curr_num > high:
return
if int(str(curr_num)[-1]) == 9:
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST FUNC_DEF IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR RETURN IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER RETURN EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXP... |
An integer has sequential digits if and only if each digit in the number is one more than the previous digit.
Return a sorted list of all the integers in the range [low, high] inclusive that have sequential digits.
Example 1:
Input: low = 100, high = 300
Output: [123,234]
Example 2:
Input: low = 1000, high = 13000
Ou... | class Solution0:
def sequentialDigits(self, low: int, high: int) -> List[int]:
nl, nh = len(str(low)), len(str(high))
ans = []
sequential = "123456789"
for n in range(nl, min(nh + 1, 10)):
start, delta = int(sequential[:n]), int("1" * n)
k_min = 0 if n > nl e... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP STRING VAR ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP... |
An integer has sequential digits if and only if each digit in the number is one more than the previous digit.
Return a sorted list of all the integers in the range [low, high] inclusive that have sequential digits.
Example 1:
Input: low = 100, high = 300
Output: [123,234]
Example 2:
Input: low = 1000, high = 13000
Ou... | class Solution:
def sequentialDigits(self, low: int, high: int) -> List[int]:
l = len(str(low))
f = len(str(high))
s = len(str(low)[0])
a = []
for i in range(l, f + 1):
while True:
t = ""
if i + s > 10:
break
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER WHILE NUMBER ASSIGN VAR STRING IF BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ... |
An integer has sequential digits if and only if each digit in the number is one more than the previous digit.
Return a sorted list of all the integers in the range [low, high] inclusive that have sequential digits.
Example 1:
Input: low = 100, high = 300
Output: [123,234]
Example 2:
Input: low = 1000, high = 13000
Ou... | class Solution:
def SequentialDigits(self, low: int, high: int) -> List[int]:
res = []
for i in range(1, 10):
for j in range(i + 1, 10):
i = i * 10 + j
if i > high:
break
if i >= low:
res.append(i)
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBE... |
An integer has sequential digits if and only if each digit in the number is one more than the previous digit.
Return a sorted list of all the integers in the range [low, high] inclusive that have sequential digits.
Example 1:
Input: low = 100, high = 300
Output: [123,234]
Example 2:
Input: low = 1000, high = 13000
Ou... | class Solution:
def sequentialDigits(self, low: int, high: int) -> List[int]:
minRange = len(str(low))
maxRange = len(str(high))
digits = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
result = []
for n in range(minRange, maxRange + 1):
for i in range(10 - n):
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUN... |
An integer has sequential digits if and only if each digit in the number is one more than the previous digit.
Return a sorted list of all the integers in the range [low, high] inclusive that have sequential digits.
Example 1:
Input: low = 100, high = 300
Output: [123,234]
Example 2:
Input: low = 1000, high = 13000
Ou... | class Solution:
def sequentialDigits(self, low: int, high: int) -> List[int]:
nums = []
max_digits = 9
for depth in range(2, max_digits + 1):
nums += self.genNum(max_digits, depth)
return [n for n in nums if n >= low and n <= high]
def genNum(self, max_digits, depth... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIG... |
An integer has sequential digits if and only if each digit in the number is one more than the previous digit.
Return a sorted list of all the integers in the range [low, high] inclusive that have sequential digits.
Example 1:
Input: low = 100, high = 300
Output: [123,234]
Example 2:
Input: low = 1000, high = 13000
Ou... | class Solution:
def sequentialDigits(self, low: int, high: int) -> List[int]:
ans = []
for ndigit in range(1, 10):
for i in range(1, 10 - ndigit + 1):
x = i
for j in range(ndigit - 1):
x = x * 10 + (i + j + 1)
if x > hi... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR VAR ... |
Igor has been into chess for a long time and now he is sick of the game by the ordinary rules. He is going to think of new rules of the game and become world famous.
Igor's chessboard is a square of size n × n cells. Igor decided that simple rules guarantee success, that's why his game will have only one type of piece... | n = int(input())
b = [input() for i in range(n)]
h = [([False] * n) for i in range(n)]
p = [[i, j] for i in range(n) for j in range(n) if b[i][j] == "o"]
v = [(["."] * (2 * n - 1)) for i in range(2 * n - 1)]
def on(x, y):
return x in range(n) and y in range(n)
def proc(dx, dy):
for pi in p:
if on(pi... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP LIST STRING BIN_OP BIN_OP NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_... |
Igor has been into chess for a long time and now he is sick of the game by the ordinary rules. He is going to think of new rules of the game and become world famous.
Igor's chessboard is a square of size n × n cells. Igor decided that simple rules guarantee success, that's why his game will have only one type of piece... | import sys
fin = sys.stdin
n = int(fin.readline())
ma = [[None]] * n
for i in range(0, n):
aux = fin.readline()
aux = aux[:-1]
ma[i] = list(aux)
r = []
for i in range(0, 2 * n - 1):
r.append(None)
r[i] = []
for j in range(0, 2 * n - 1):
r[i].append("x")
for i in range(0, n):
for j i... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST LIST NONE VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR NONE ASSIGN V... |
Igor has been into chess for a long time and now he is sick of the game by the ordinary rules. He is going to think of new rules of the game and become world famous.
Igor's chessboard is a square of size n × n cells. Igor decided that simple rules guarantee success, that's why his game will have only one type of piece... | import sys
f = sys.stdin
n = int(f.readline().strip())
fig = []
place = []
for i in range(n):
place.append([-1] * n)
for i in range(n):
s = f.readline().strip()
for k in range(len(s)):
if s[k] == "o":
fig.append((k, i))
place[k][i] = -1
elif s[k] == "x":
... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR ASS... |
Igor has been into chess for a long time and now he is sick of the game by the ordinary rules. He is going to think of new rules of the game and become world famous.
Igor's chessboard is a square of size n × n cells. Igor decided that simple rules guarantee success, that's why his game will have only one type of piece... | s = int(input())
opos = []
xpos = []
dpos = []
for i in range(s):
x = input()
for j in range(s):
if x[j] == "o":
opos.append([i, j])
elif x[j] == "x":
xpos.append([i, j])
else:
dpos.append([i, j])
ddifs = {}
for i in dpos:
a = i[0]
b = i[1]
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR LIST VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR DICT FOR VAR ... |
Igor has been into chess for a long time and now he is sick of the game by the ordinary rules. He is going to think of new rules of the game and become world famous.
Igor's chessboard is a square of size n × n cells. Igor decided that simple rules guarantee success, that's why his game will have only one type of piece... | def main():
n = int(input())
d = [input() for i in range(n)]
figures = []
for i in range(n):
for j in range(n):
if d[i][j] == "o":
figures.append((i, j))
result = [["x" for i in range(2 * n - 1)] for j in range(2 * n - 1)]
result[n - 1][n - 1] = "o"
for i ... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER V... |
Igor has been into chess for a long time and now he is sick of the game by the ordinary rules. He is going to think of new rules of the game and become world famous.
Igor's chessboard is a square of size n × n cells. Igor decided that simple rules guarantee success, that's why his game will have only one type of piece... | import sys
n = int(input())
s = [input() for i in range(n)]
a = [([1] * (2 * n)) for i in range(2 * n)]
for i in range(n):
for j in range(n):
if s[i][j] != "o":
continue
for x in range(n):
for y in range(n):
if s[x][y] == ".":
a[n + x - i]... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ST... |
Igor has been into chess for a long time and now he is sick of the game by the ordinary rules. He is going to think of new rules of the game and become world famous.
Igor's chessboard is a square of size n × n cells. Igor decided that simple rules guarantee success, that's why his game will have only one type of piece... | from sys import stdin
n = int(stdin.readline())
board = []
for x in range(n):
board.append(list(stdin.readline().strip()))
moves = {y: {x: (True) for x in range(-n + 1, n)} for y in range(-n + 1, n)}
for x in range(n):
for y in range(n):
if board[x][y] == "o":
for a in range(n):
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING FO... |
The Zoo in the Grid Kingdom is represented by an infinite grid. The Zoo has n observation binoculars located at the OX axis. For each i between 1 and n, inclusive, there exists a single binocular located at the point with coordinates (i, 0). There are m flamingos in the Zoo, located at points with positive coordinates.... | from sys import *
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def normalize_rational(num, den):
if num ^ den < 0 and num > 0 or num ^ den > 0 and num < 0:
num = -num
den = -den
g = gcd(abs(num), abs(den))
num //= g
den //= g
return num, den
l = stdin... | FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF IF BIN_OP VAR VAR NUMBER VAR NUMBER BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_C... |
The Zoo in the Grid Kingdom is represented by an infinite grid. The Zoo has n observation binoculars located at the OX axis. For each i between 1 and n, inclusive, there exists a single binocular located at the point with coordinates (i, 0). There are m flamingos in the Zoo, located at points with positive coordinates.... | n, m = map(int, input().split())
l = []
anss = [1] * (n + 1)
for i in range(m):
l.append(list(map(int, input().split())))
for i in range(m - 1):
for j in range(i + 1, m):
sx = l[i][0] - l[j][0]
sy = l[i][1] - l[j][1]
ans = 2
if sx:
if sy:
x = (l[i][0] ... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN... |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
def revert(s):
ans = ""
for x in s:
if x == "1":
ans += "0"
else:
ans += "1"
return ans
def helper(n):
if n == 1:
... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR STRING VAR STRING RETURN VAR FUNC_DEF IF VAR NUMBER RETURN STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP VAR STRING FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
s = [0]
def findKthBit(self, n: int, k: int) -> str:
while len(self.s) < k:
self.s = self.s + [1] + [(n ^ 1) for n in self.s[::-1]]
return str(self.s[k - 1]) | CLASS_DEF ASSIGN VAR LIST NUMBER FUNC_DEF VAR VAR WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR LIST NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
return self.solv(n, k)
def solv(sef, n, k):
i = 1
lst = ["0"]
ans = "0"
ki = 1
if k == 1:
return "0"
while i < n + 1:
ans = "1"
lst.append(ans)
k... | CLASS_DEF FUNC_DEF VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST STRING ASSIGN VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER RETURN STRING WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMB... |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
def invert(bin):
bin = list(bin)
for i in range(len(bin)):
if bin[i] == "1":
bin[i] = "0"
else:
bin[i] = "1"
return "".join(bin)
... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING RETURN FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP ... |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
d = dict()
d[0] = [0]
for i in range(1, n + 1):
d[i] = d[i - 1] + [1] + [(1 - x) for x in d[i - 1]][::-1]
return str(d[n][k - 1]) | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER LIST NUMBER BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
s = "0"
if n == 1:
return "0"
for i in range(1, n):
s_i = s[::-1]
s = s + "1" + "".join([("1" if c == "0" else "0") for c in s_i])
return s[k - 1] | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR STRING IF VAR NUMBER RETURN STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR STRING FUNC_CALL STRING VAR STRING STRING STRING VAR VAR RETURN VAR BIN_OP VAR NUMBER VAR |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
full = [0]
for _ in range(n - 1):
full = full + [1] + [((x + 1) % 2) for x in full][::-1]
return str(full[k - 1]) | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR LIST NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
def invert(s):
temp = ""
for i in range(len(s)):
if s[i] == "1":
temp = temp + "0"
else:
temp = temp + "1"
return temp
s = "0"
... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR STRING RETURN VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR STRING V... |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | bins = [[0]]
for _ in range(20):
bins.append(bins[-1] + [1] + [(1 - x) for x in reversed(bins[-1])])
class Solution:
def findKthBit(self, n: int, k: int) -> str:
return str(bins[n - 1][k - 1]) | ASSIGN VAR LIST LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER LIST NUMBER BIN_OP NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER CLASS_DEF FUNC_DEF VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def invert(self, t):
ret = ""
for i in t:
if i == "0":
ret += "1"
else:
ret += "0"
return ret
def findKthBit(self, n: int, k: int) -> str:
i = 1
l = list()
l.append("0")
while i <= n... | CLASS_DEF FUNC_DEF ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR STRING VAR STRING RETURN VAR FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING WHILE VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR STRING VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR... |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
s = ""
def recurse(n):
nonlocal s
if n <= 1:
return "0"
else:
_str = recurse(n - 1)
s = _str + "1" + self.reverse(self.invert(_str))
retu... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR STRING FUNC_DEF IF VAR NUMBER RETURN STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR STRING FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF RETURN FUNC_CALL STRING VAR STRING STRING STRING VAR VAR FUN... |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
def helper(res, k):
if k == 0:
return res
invert = [("1" if i == "0" else "0") for i in res]
invert = "".join(invert)
res = res + "1" + invert[::-1]
return helper(res, k... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR VAR STRING STRING STRING VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR BIN_OP BIN_OP VAR STRING VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER RETURN VAR BIN_OP VAR NUMBER VAR |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
s = "011"
if k < 4:
return s[k - 1]
d = {"0": "1", "1": "0"}
for i in range(n):
s += "1"
if len(s) == k:
return "1"
else:
for x in s[:-1][::-1... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR STRING IF VAR NUMBER RETURN VAR BIN_OP VAR NUMBER ASSIGN VAR DICT STRING STRING STRING STRING FOR VAR FUNC_CALL VAR VAR VAR STRING IF FUNC_CALL VAR VAR VAR RETURN STRING FOR VAR VAR NUMBER NUMBER VAR VAR VAR IF FUNC_CALL VAR VAR VAR RETURN VAR VAR VAR |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
def operator(s):
t = reversed([("0" if i == "1" else "1") for i in s])
return s + "1" + "".join(t)
s = "0"
while len(s) < k:
s = operator(s)
return s[k - 1] | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR STRING STRING STRING VAR VAR RETURN BIN_OP BIN_OP VAR STRING FUNC_CALL STRING VAR ASSIGN VAR STRING WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR BIN_OP VAR NUMBER VAR |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
def reverse_invert(array: List[str]) -> List[str]:
res = []
for ind in range(len(array) - 1, -1, -1):
res.append("1" if array[ind] == "0" else "0")
return res
bits = ["0"]
for ... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR STRING STRING STRING RETURN VAR VAR VAR ASSIGN VAR LIST STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP LIST STRING FUNC_CALL VAR VAR RETURN VAR BIN... |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
curr = "0"
for x in range(2, n + 1):
nxt = curr + "1" + self.invert(curr)[::-1]
curr = nxt
return curr[k - 1]
def invert(self, s):
return "".join([("1" if x == "0" else "0") for x in s]) | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR STRING FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR RETURN VAR BIN_OP VAR NUMBER VAR FUNC_DEF RETURN FUNC_CALL STRING VAR STRING STRING STRING VAR VAR |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
cur = "0"
while len(cur) < k:
cur = cur + "1" + "".join("1" if b == "0" else "0" for b in reversed(cur))
return cur[k - 1] | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR STRING WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR STRING FUNC_CALL STRING VAR STRING STRING STRING VAR FUNC_CALL VAR VAR RETURN VAR BIN_OP VAR NUMBER VAR |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
def inner(n, k):
if n == 1:
re = 0
elif k == 2 ** (n - 1):
re = 1
elif k < 2 ** (n - 1):
re = inner(n - 1, k)
else:
re = inner(n - 1,... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR VAR NUMBER RETURN VAR RETURN FUNC_... |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
def negVal(val):
lenVal = len(val)
mask = int("1" * lenVal, 2)
val = int(val, 2)
neg = val ^ mask
lenNeg = len(bin(neg)) - 2
neg = "0" * (lenVal - lenNeg) + bin(neg)[2:]
... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER RETURN VAR NUM... |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
def helper(memo):
ans = ""
for c in memo:
if c == "0":
ans += "1"
else:
ans += "0"
return ans
memo = "0"
for i in range(... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR STRING VAR STRING RETURN VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR STRING FUNC_CALL VAR VAR NUMBER RETURN VAR BIN_OP VAR NUMBER VAR |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
def revinv(x):
ans = []
for c in x:
if c == "0":
ans.append("1")
else:
ans.append("0")
return "".join(reversed(ans))
s = "0"
... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING RETURN FUNC_CALL STRING FUNC_CALL VAR VAR ASSIGN VAR STRING WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR STRING FUNC_CALL VAR VAR RETURN VAR BIN_OP VAR NUMBER VAR |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def invert(self, s):
out = ""
for c in s:
if c == "0":
out += "1"
if c == "1":
out += "0"
return out
def reverse(self, s):
return s[::-1]
def findKthBit(self, n: int, k: int) -> str:
l = []
... | CLASS_DEF FUNC_DEF ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR STRING IF VAR STRING VAR STRING RETURN VAR FUNC_DEF RETURN VAR NUMBER FUNC_DEF VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR STRING FUNC_CALL VAR FUNC_CALL VA... |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
def invert(s):
return "".join([("1" if c == "0" else "0") for c in s])
def revStr(s):
return "".join(list(reversed(s)))
counter = 1
x = "0"
while counter != n:
x = x + "1" + r... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF RETURN FUNC_CALL STRING VAR STRING STRING STRING VAR VAR FUNC_DEF RETURN FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR BIN_OP VAR NUMBER VAR |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | def invert(s):
return bin(int(s, 2) ^ int("1" * len(s), 2))[2:]
def reverse(s):
return s[::-1]
class Solution:
def findKthBit(self, n: int, k: int) -> str:
S = [None] * n
S[0] = "0"
for i in range(1, n):
S[i] = S[i - 1] + "1" + reverse(invert(S[i - 1]))
retur... | FUNC_DEF RETURN FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR NUMBER NUMBER FUNC_DEF RETURN VAR NUMBER CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER STR... |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
l = [0] * (n + 1)
for i in range(1, n + 1):
l[i] = 2 * l[i - 1] + 1
def helper(n, k, f):
m = l[n]
if n == 1:
return 0 ^ f
if k == m // 2 + 1:
return ... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR VAR IF VAR NUMBER RETURN BIN_OP NUMBER VAR IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN BIN_OP NUMBER VAR IF... |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
def reverseInvert(string: str) -> str:
output = []
for char in string:
if char == "0":
output.append("1")
else:
output.append("0")
output... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF VAR ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR RETURN FUNC_CALL STRING VAR VAR FUNC_DEF VAR IF VAR NUMBER RETURN STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP VAR STRING FUNC_CALL VAR VAR V... |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
return str(k // (k & -k) >> 1 & 1 ^ (k & 1 ^ 1))
def findKthBit_logn(self, n: int, k: int) -> str:
cur, flip = 1 << n - 1, 0
while k > 1:
if k & k - 1 == 0:
return str(flip ^ 1)
if k > ... | CLASS_DEF FUNC_DEF VAR VAR RETURN FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR FUNC_DEF VAR VAR ASSIGN VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VA... |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
dp = ["0"] * n
for i in range(1, n):
dp[i] = (
dp[i - 1] + "1" + "".join([str(1 - int(n)) for n in dp[i - 1]])[::-1]
)
return dp[-1][k - 1] | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER STRING FUNC_CALL STRING FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER RETURN VAR NUMBER BIN_OP VAR NUMBER VAR |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
s = []
for i in range(n):
if i == 0:
s.append(["0"])
else:
temp = s[i - 1].copy()
for j in range(len(temp)):
if temp[j] == "0":
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR LIST STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR LIST FOR VAR VAR BIN... |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
def invert(x):
return [(0 if i == 1 else 1) for i in x]
S = [0]
i = 1
while i < n and len(S) < k:
S.append(1)
S.extend(invert(S[:-1])[::-1])
i += 1
return str(S[k -... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF RETURN VAR NUMBER NUMBER NUMBER VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER WHILE VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
memo = {}
def dp(s):
if s in memo:
return memo[s]
if s == 1:
return "0"
temp = dp(s - 1)
res = temp + "1" + "".join([("0" if b == "1" else "1") for b in temp... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT FUNC_DEF IF VAR VAR RETURN VAR VAR IF VAR NUMBER RETURN STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR STRING FUNC_CALL STRING VAR STRING STRING STRING VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
sn = ["0"]
for i in range(1, n):
nx = sn[i - 1] + "1" + self.reverse(self.invert(sn[i - 1]))
sn.append(nx)
return sn[-1][k - 1]
def invert(self, s):
return "".join("0" if _ == "1" else "1" for ... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_DEF RETURN FUNC_CALL STRING VAR STRING STRING STRING VAR VAR FUNC... |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
s = "0"
while n > 1:
p = ""
for l in s[::-1]:
p += "1" if l == "0" else "0"
s = s + "1" + p
n -= 1
return s[k - 1] | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR STRING WHILE VAR NUMBER ASSIGN VAR STRING FOR VAR VAR NUMBER VAR VAR STRING STRING STRING ASSIGN VAR BIN_OP BIN_OP VAR STRING VAR VAR NUMBER RETURN VAR BIN_OP VAR NUMBER VAR |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
s2 = "011"
if k <= 3:
return s2[k - 1]
if k == 2 ** (n - 1):
return "1"
elif k < 2 ** (n - 1):
return self.findKthBit(n - 1, k)
else:
ans = self.findKthBit(n - 1, 2**... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR STRING IF VAR NUMBER RETURN VAR BIN_OP VAR NUMBER IF VAR BIN_OP NUMBER BIN_OP VAR NUMBER RETURN STRING IF VAR BIN_OP NUMBER BIN_OP VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR VAR RETURN VAR STRING STRING ... |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
m = 2**n - 1
if k == 1 or 0 < m - k < 4:
return "0"
if k == m or k < 5:
return "1"
s = [0]
for _ in range(n - 1):
s += [1] + [(x ^ 1) for x in reversed(s)]
return str(s[k... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER RETURN STRING IF VAR VAR VAR NUMBER RETURN STRING ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP... |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
dp = [[]] * n
dp[0] = [0]
for i in range(1, n):
dp[i] = dp[i - 1] + [1] + list(reversed([(v ^ 1) for v in dp[i - 1]]))
return str(dp[-1][k - 1]) | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST LIST VAR ASSIGN VAR NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
i = n - 1
invert = False
while i > 0:
half_len = (2 ** (i + 1) - 1) // 2
if k == half_len + 1:
return "1" if not invert else "0"
if k > half_len:
k = half_len - (... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER RETURN VAR STRING STRING IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER RETURN... |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
x = "0"
for i in range(1, n):
x = (
x
+ "1"
+ "".join(list(map(lambda x: "1" if x == "0" else "0", x))[::-1])
)
return x[k - 1] | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR STRING FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR STRING STRING STRING VAR NUMBER RETURN VAR BIN_OP VAR NUMBER VAR |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
if n == 1:
return "0"
if n == 2:
return ["0", "1", "1"][k - 1]
record = [0, 1, 1]
for i in range(n - 2):
record = record + [1] + record
l = len(record)
record[l /... | CLASS_DEF FUNC_DEF VAR VAR IF VAR NUMBER RETURN STRING IF VAR NUMBER RETURN LIST STRING STRING STRING BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP... |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
def invert(data):
ans = ""
for val in data:
if val == "1":
ans += "0"
else:
ans += "1"
return ans
res = [""] * (n + 1)
r... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR STRING VAR STRING RETURN VAR ASSIGN VAR BIN_OP LIST STRING BIN_OP VAR NUMBER ASSIGN VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR VAR BIN_OP VAR ... |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
A = [0]
while k > len(A):
A.append(1)
for i in range(len(A) - 2, -1, -1):
A.append(A[i] ^ 1)
return str(A[k - 1]) | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST NUMBER WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
def reverse(s):
return "".join([s[len(s) - 1 - i] for i in range(len(s))])
def invert(s):
return "".join([("1" if s[i] == "0" else "0") for i in range(len(s))])
def findNthStr(n1):
if n1 == 1... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF RETURN FUNC_CALL STRING VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL STRING VAR VAR STRING STRING STRING VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER RETURN STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER... |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
def invert(l):
result = []
for item in l:
if item == "0":
result.append("1")
else:
result.append("0")
return result
string = "0"... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING RETURN VAR ASSIGN VAR STRING WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_C... |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
def invert(n):
s = ""
for char in n:
if char == "0":
s += "1"
else:
s += "0"
return s
def generater(n):
dp = [-1] * ... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR STRING VAR STRING RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR VAR BIN_OP VAR NUMBE... |
Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
For example, t... | class Solution:
def findKthBit(self, n: int, k: int) -> str:
s = []
s.append("0")
for i in range(1, n):
ans = s[i - 1] + "1"
temp = ""
for j in s[i - 1]:
if j == "0":
temp += "1"
else:
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER STRING ASSIGN VAR STRING FOR VAR VAR BIN_OP VAR NUMBER IF VAR STRING VAR STRING VAR STRING ASSIGN VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR NUMBER BIN_OP VAR NU... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.