description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
k = n // 2
l = arr[:k]
p = arr[k:]
arr.clear()
for i in range(len(p)):
arr.append(l[i])
arr.append(p[i])
return arr | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
l = []
x = n // 2
for i in range(x):
print
l.extend([arr[i], arr[i + x]])
arr[:] = l | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
for i in range(n // 2):
arr[i] += arr[n // 2 + i] * 10000
for i in range(n // 2 - 1, -1, -1):
arr[2 * i + 1] = arr[i] // 10000
arr[2 * i] = arr[i] % 10000 | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR BIN_OP VAR VAR NUMBER |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
mid = n // 2
for i in range(mid):
x = arr.pop(i + mid)
arr.insert(2 * i + 1, x)
return arr | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR RETURN VAR |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
L = n // 2
l1 = arr[0:L]
l2 = arr[L:n]
a = []
for i in range(L):
a.append(l1[i])
a.append(l2[i])
arr.clear()
arr.extend(a)
return arr | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR RETURN VAR |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
k = n // 2
h1 = arr[:k]
h2 = arr[k:]
arr.clear()
for i in range(n // 2):
arr += [h1[i]]
arr += [h2[i]]
return arr | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR LIST VAR VAR VAR LIST VAR VAR RETURN VAR |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
l = n // 2
p = []
q = []
for i in range(l):
p.append(arr[i])
for i in range(l, n):
q.append(arr[i])
arr[0] = p[0]
px = 1
qx = 0
for i in range(1, n):
if i % 2 ... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER ASSI... |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
ai = 0
bi = 0
def isEqual(a):
b = 0
for _ in range(len(B)):
if A[a] != B[b]:
return False
b += 1
a = (a + 1) % len(A)
return True
sta... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF FUN... |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
for i in B:
if i not in A:
return -1
S = A
c = 1
while len(S) < len(B):
S = S + A
c = c + 1
if B in S:
return c
elif B in S + A:
return c + 1
... | CLASS_DEF FUNC_DEF FOR VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR RETURN VAR IF VAR BIN_OP VAR VAR RETURN BIN_OP VAR NUMBER RETURN NUMBER |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
cnt = 0
C = ""
while len(C) < len(B):
C += A
cnt += 1
if B in C:
return cnt
else:
C += A
cnt += 1
if B in C:
return cnt
else:
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR STRING WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR RETURN VAR VAR VAR VAR NUMBER IF VAR VAR RETURN VAR RETURN NUMBER |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
x = A * (len(B) // len(A) + len(A))
if B not in x:
return -1
c = 1
x = A
while B not in x:
x = x + A
c += 1
return c | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
count = 1
if A.find(B) > -1:
return count
s = A
found = False
while len(s) < 2 * len(B):
s = s + A
count += 1
if s.find(B) != -1:
found = True
break
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR RETURN VAR RETURN NUMBER |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, a, b):
x = len(a)
y = len(b)
if x > y and b in a:
return 1
elif x > y and b in a * 2:
return 2
elif x > y:
return -1
elif y % x == 0 and b == a * (y // x):
return y // x
elif... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR RETURN BIN_OP VAR VAR IF VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN BIN_OP ... |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
ans = -1
for i in range(len(A)):
index = i
found = True
for j in range(len(B)):
if A[index % len(A)] != B[j]:
found = False
break
index += 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR VAR VAR NUMBER RET... |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
start_ix = A.find(B[0])
if start_ix == -1:
return -1
ans = 1
ans += (start_ix + len(B)) // len(A)
if ans == 1 and B not in A:
ans += 1
S = A * ans
if B in S:
return ans if S.find(... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VA... |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
S = A
ans = 1
while len(S) < len(B):
S += A
ans += 1
if B in S:
return ans
elif B in S + A:
return ans + 1
return -1 | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR RETURN VAR IF VAR BIN_OP VAR VAR RETURN BIN_OP VAR NUMBER RETURN NUMBER |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
m = len(A)
n = len(B)
count = 0
found = False
for i in range(m):
j = i
k = 0
count = 1
while k < n and A[j] == B[k]:
if k == n - 1:
found = True
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR... |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
i = 0
s = A
while B not in s and len(s) < 2 * len(B):
if B[i] not in A:
return -1
s += A
i += 1
if B in s:
return i + 1
else:
return -1 | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR RETURN NUMBER VAR VAR VAR NUMBER IF VAR VAR RETURN BIN_OP VAR NUMBER RETURN NUMBER |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
s = ""
if B in A:
return 1
nA = len(A)
nB = len(B)
nS = 0
cnt = 0
while nS < nB:
s += A
nS += nA
cnt += 1
if B in s:
return cnt
elif B in s... | CLASS_DEF FUNC_DEF ASSIGN VAR STRING IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR RETURN VAR IF VAR BIN_OP VAR VAR RETURN BIN_OP VAR NUMBER RETURN NUMBER |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
count = 0
string = ""
if set(B) <= set(A):
while B not in string:
string += A
count += 1
if len(string) >= len(B):
break
if B in string:
re... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR STRING IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR RETURN VAR IF VAR BIN_OP VAR VAR RETURN BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
c = 0
i = 0
while i < len(B) - len(A):
if A == B[i : i + len(A)]:
c += 1
i = i + len(A) - 1
i += 1
if B in A * c:
return c
elif B in A + A * c or B in A * c + A:
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR VAR RETURN VAR IF VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR ... |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, a, b):
i = 0
ans = 1
while i < len(a):
f = 0
if a[i] == b[0]:
j = i
k = 0
while k < len(b):
if a[j] != b[k]:
f = 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER I... |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
S = A
count = 1
for i in range(400):
if B in S:
return count
else:
S = S + A
count += 1
return -1 | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR RETURN VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER RETURN NUMBER |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
i = A.find(B[0])
j = (i + len(B)) / len(A)
if B in A * (int(j) + 2):
if int(j) < j:
j = int(j + 1)
else:
j = int(j)
if j == 1 and B not in A:
return j + 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR RETURN BIN_OP VAR NUMBER RETURN... |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
str = A
num = 1
while B not in str:
if len(str) > len(B) and num > 3:
return -1
str += A
num = num + 1
return num | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER RETURN NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
x = max(len(B) // len(A), len(A) // len(B))
for i in range(2):
if B in A * (x + i):
return x + i
break
return -1 | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR BIN_OP VAR VAR RETURN BIN_OP VAR VAR RETURN NUMBER |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
nA = len(A)
nB = len(B)
for i in range(nA):
k = i
cnt = 1
isValid = True
for j in range(nB):
if A[k] != B[j]:
isValid = False
k = (k + 1) % nA
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR NUMBER IF VAR IF VAR NUMBER VAR NUMBER RETURN... |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
c = 1
x = A
while A.find(B) == -1:
c += 1
A += x
if len(A) > len(B) and A.find(B) == -1:
return -1
if A.find(B) == -1:
return -1
return c | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN VAR |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
i = 0
count = 1
s = A
while i < len(B) / len(A) + 2:
if s.find(B) != -1:
return count
s += A
count += 1
i += 1
return -1 | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN VAR VAR VAR VAR NUMBER VAR NUMBER RETURN NUMBER |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
if B in A:
return 1
cnt = 1
temp = A
while len(temp) <= len(B):
if B in temp:
return cnt
else:
cnt += 1
temp += A
if B in temp:
return ... | CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR RETURN VAR VAR NUMBER VAR VAR IF VAR VAR RETURN VAR VAR VAR VAR NUMBER IF VAR VAR RETURN VAR RETURN NUMBER |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
if B in A:
return 1
i = 2
a = ""
while len(a) <= len(B):
a = A * i
i += 1
if B in a:
return i - 1
return -1 | CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR RETURN BIN_OP VAR NUMBER RETURN NUMBER |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
reps = 1
index_a = len(A) - 1
index_b = len(B) - 1
current_a = index_a
while index_a >= 0:
while B[index_b] == A[current_a]:
current_a -= 1
index_b -= 1
if index_b < 0:
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL ... |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
a = set(A)
b = set(B)
if b.issubset(a):
S = ""
ans = 0
while len(S) < len(B):
S += A
ans += 1
if B in S:
return ans
elif B in S + A:
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR RETURN VAR IF VAR BIN_OP VAR VAR RETURN BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
for i in range(1, len(B) // len(A) + 3):
if B in A * i:
return i
return -1 | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR VAR RETURN VAR RETURN NUMBER |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
for i in range(0, len(B)):
if B[i] not in A:
return -1
S = ""
S = S + A
c = 1
if B in S:
return c
if B in S + A:
return c + 1
f = 0
while len(S) <= len(B):... | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR RETURN NUMBER ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR VAR RETURN VAR IF VAR BIN_OP VAR VAR RETURN BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN V... |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
n = len(B) // len(A) + 1
start = 0
end = n + 1
mid = start + (end - start) // 2
ans = -1
while start <= end:
p = A * mid
if B in p:
ans = mid
end = mid - 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR ... |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
l1 = len(A)
l2 = len(B)
K = 1
s = A
while (K - 2) * l1 + 2 <= l2:
if K * l1 >= l2:
for i in range(K * l1 - l2 + 1):
if s[i : i + l2] == B:
return K
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR IF BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR VAR RETURN VAR VAR NUMBER VAR VAR RETURN NUMBER |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
n1 = len(A)
n2 = len(B)
ans1 = -1
for k in range(n1):
i = k
ans = 0
for j in range(n2):
if i == 0:
ans += 1
if A[i] != B[j]:
ans = ... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER FUNC_CALL VA... |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
s = set(A)
for i in B:
if i not in s:
return -1
if len(B) >= len(A):
n = len(B) // len(A)
A = A * n
a = A * (n + 1)
if B in A:
return n
elif B ... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR VAR RETURN VAR IF VAR VAR RETURN BIN_OP VAR NUMBER RETURN NUMBER RETU... |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, a, b):
st = a
m = len(b)
flag = 0
count = 0
while len(a) < len(b):
count += 1
a += st
if b in a:
count += 1
return count
else:
a += st
count += 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR IF VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR NUMBER IF VAR VAR RETURN BIN_OP VAR NUMBER RETURN NUMBER |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
x = A * 10**3
if B not in x:
return -1
c = 1
x = A
while B not in x:
x = x + A
c += 1
return c | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR BIN_OP NUMBER NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
n, m = len(A), len(B)
start = None
for i in range(n):
if A[i] == B[0]:
new = len(A[i:])
if A[i:] == B[:new]:
start = new
break
if start == None:
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NONE FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR IF VAR NONE RETURN NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR BIN_OP VAR VAR... |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
if len(A) > len(B):
return 2
else:
a = int(len(B) / len(A))
if B in A * a:
return a
elif B in A * (a + 1):
return a + 1
return -1 | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR RETURN VAR IF VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER RETURN NUMBER |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
ans = -1
for i in range(len(A)):
j = 0
tempans = self.Helper(A, B, i, j)
if tempans != -1:
return tempans
return ans
def Helper(self, A, B, i, j):
n = len(A)
count = 0
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER RETURN VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ... |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def findSubString(self, A, B):
a_len = len(A)
b_len = len(B)
repeat = b_len - a_len
if b_len - a_len == 0:
repeat = 1
all_done = False
for i in range(repeat):
all_done = False
for j in range(a_len):
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR RETURN NUMBER... |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def issubstring(self, str2, rep):
if str2 in rep:
return True
return False
def minRepeats(self, A, B):
ans = 1
S = A
while len(S) < len(B):
S += A
ans += 1
if self.issubstring(B, S):
return ans
... | CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR RETURN VAR IF FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN BIN_OP VAR NUMBER RETURN NUMBER |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def findChar(self, A, B):
for b in B:
if b not in A:
return False
else:
return True
def minRepeats(self, A, B):
res = self.findChar(A, B)
if res:
i = 1
temp = A
l = len(A) + 1
... | CLASS_DEF FUNC_DEF FOR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETU... |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
count = 1
if A == B and len(A) == len(B):
return count
elif A == B[0 : len(A)]:
s = str(A)
while len(A) < len(B):
A = A + s
count = count + 1
elif len(A) > len(B):
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER IF VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR IF VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VA... |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
n = len(A)
m = len(B)
for i in range(1, m // n + 2):
if B in A * i:
return i
if B in A + A:
return 2
if B in A:
return 1
return -1 | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR RETURN VAR IF VAR BIN_OP VAR VAR RETURN NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
dic2 = {}
for i in range(len(B)):
if dic2.get(B[i]):
dic2[B[i]] += 1
else:
dic2[B[i]] = 1
for keyy in dic2.keys():
if keyy not in A:
return -1
i = 0
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF... |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
a = len(A)
b = len(B)
for i in range(a):
if A[i:] != B[: min(a - i, b)]:
continue
t = 1
j = min(a - i, b)
valid = True
while j < b:
if B[j : min(j + a, b)]... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VA... |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
if len(A) >= len(B):
if B in A:
return 1
A += A
if B in A:
return 2
return -1
c = 1
st = A
while len(A) <= len(B):
if B in A:
retur... | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR RETURN VAR VAR VAR VAR NUMBER IF VAR VAR RETURN VAR RETURN NUMBER |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
n = len(A)
m = len(B)
count = 1
repeated_A = A
while len(repeated_A) < m:
repeated_A += A
count += 1
if B in repeated_A:
return count
repeated_A += A
count += 1
if... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR RETURN VAR VAR VAR VAR NUMBER IF VAR VAR RETURN VAR RETURN NUMBER |
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1.
Example 1:
Input:
A = "abcd"
B = "cdabcdab"
Output:
3
Explanation:
Repeating A three times (abcdabcdabcd),
B is a substring of it. B is not a substring
of A when... | class Solution:
def minRepeats(self, A, B):
max_len = len(B) // len(A) + 2
for i in range(1, max_len + 1):
if B in A * i:
return i
return -1 | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR RETURN VAR RETURN NUMBER |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Solution:
def wordBoggle(self, board, dictionary):
ans = set()
for word in dictionary:
self.searchWord(ans, word, board)
return list(ans)
def searchWord(self, ans, word, board):
visited = [([False] * len(board[0])) for _ in range(len(board))]
idx = 0
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF ... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Solution:
def wordBoggle(self, board, dictionary):
n, m = len(board), len(board[0])
used = [[(False) for _ in range(m)] for _ in range(n)]
l = []
ls = set()
def dfs(row, col, s, k):
if len(s) <= k:
return True
flag = False
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR NUMBER IF NUMBER VAR VAR NUMBER VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR ASSIGN... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Solution:
def wordBoggle(self, board, dictionary):
ans = []
rows = len(board)
cols = len(board[0])
def dfs(r, c, i, wor, path):
if i == len(wor):
return True
if (
r < 0
or c < 0
or r >= ro... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR ... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Solution:
def wordBoggle(self, board, dictionary):
def dfs(k, board, i, j, R, C):
n = len(k)
bool = False
if k[0] == board[i][j] and n == 1:
return True
if k[0] == board[i][j]:
temp = board[i][j]
board[i]... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR STRING ASSIGN VAR LIST LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER LIST BIN_OP VAR NUMBER VAR LIST BIN_OP VAR NUMBER BIN_OP VAR N... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Trie:
def __init__(self):
self.T = {}
def add(self, word):
t = self.T
for c in word:
if c not in t:
t[c] = {}
t = t[c]
t["#"] = True
class Solution:
def wordBoggle(self, board, dictionary):
t = Trie()
res = []... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF ASSIGN VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR DICT ASSIGN VAR VAR VAR ASSIGN VAR STRING NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Solution:
def dfs(self, board, visited, word, root, r, c):
if len(word) == 0:
return True
i, j = root
visited.add((i, j))
neighbours = []
if i > 0:
neighbours.append((i - 1, j))
if j > 0:
neighbours.append((i, j - 1))
... | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR ... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Solution:
def wordBoggle(self, board, dictionary):
def isvalid(x1, y1):
return x1 >= 0 and x1 < ROWS and y1 >= 0 and y1 < COLS
def check(x, y, index):
visited.add((x, y))
if index == len(word) - 1:
visited.remove((x, y))
re... | CLASS_DEF FUNC_DEF FUNC_DEF RETURN VAR NUMBER VAR VAR VAR NUMBER VAR VAR FUNC_DEF EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR RETURN NUMBER FOR VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP V... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Trie:
def __init__(self):
self.root = Node()
def insert(self, st):
curr = self.root
for i in range(len(st)):
if curr.childs[ord(st[i]) - ord("A")] == None:
curr.childs[ord(st[i]) - ord("A")] = Node()
curr = curr.childs[ord(st[i]) - ord("A")... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NONE ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Solution:
def recur_util(self, cur_ind, board, word):
res = False
visited = [([False] * len(board[0])) for _ in range(len(board))]
opts = [[0, 1], [1, 0], [1, 1], [0, -1], [-1, 0], [-1, -1], [1, -1], [-1, 1]]
def recur(x, y, visited, w_ind, word):
if x < 0 or y < ... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER FUNC_DEF IF VAR NUMBER V... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class TrieNode:
def __init__(self):
self.children = {}
self.end_of_word = False
class Trie:
def __init__(self):
self.root = TrieNode()
def add_word(self, word):
cur = self.root
for c in word:
if c not in cur.children:
cur.children[c] =... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR F... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | def dfs(mat, i, j, n, m, st, l, k):
global visited
global dirn
if k >= l:
return True
if mat[i][j] != st[k]:
return False
if k == l - 1:
return True
visited[i][j] = True
res = False
for d in dirn:
u = i + d[0]
v = j + d[1]
if u >= 0 and v >... | FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR VAR VAR RETURN NUMBER IF VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL ... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class TrieNode:
def __init__(self):
self.children = {}
self.is_word = False
class Trie:
def __init__(self):
self.root = TrieNode()
def insert(self, word):
cur = self.root
for letter in word:
if letter not in cur.children:
cur.children[... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR FOR VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR RETURN VAR CLASS_DEF FUNC_DEF ... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Solution:
def wordBoggle(self, board, dictionary):
self.R = len(board)
self.C = len(board[0])
self.board = board
res = set()
for word in dictionary:
visited = [[(False) for _ in range(self.C)] for _ in range(self.R)]
found = False
fo... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBE... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Solution:
def wordBoggle(self, board, dictionary):
class TrieNode:
def __init__(self):
self.child = {}
self.Eow = False
def insert(word, Trie):
for w in word:
if w not in Trie.child:
Trie.child[w] =... | CLASS_DEF FUNC_DEF CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER FUNC_DEF FOR VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR BIN... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Solution:
def find(self, board, word):
visited = [[(False) for i in range(len(board[0]))] for j in range(len(board))]
def dfs(r, c, pos):
if pos == len(word):
return True
if (
0 <= r < len(board)
and 0 <= c < len(board[0... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class TrieNode:
def __init__(self):
self.children = [None] * 26
self.isEndOfWord = False
class Solution:
def __init__(self):
self.root = TrieNode()
self.tempx = [0, 0, -1, 1, 1, -1, -1, 1]
self.tempy = [1, -1, 0, 0, 1, -1, 1, -1]
self.ans = set()
def word... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NONE NUMBER ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_DEF FOR VAR VAR EXPR FUNC_CALL... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Solution:
def createTrie(self, words):
trie = {}
for word in words:
root = trie
for c in word:
if c not in root:
root[c] = {}
root = root[c]
root["#"] = "#"
return trie
def wordBoggle(self, bo... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR DICT ASSIGN VAR VAR VAR ASSIGN VAR STRING STRING RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Solution:
def wordBoggle(self, board, dictionary):
def dfs(board, word, v, i, j, indx):
if indx == len(word):
return True
if (
i >= 0
and i < len(board)
and j >= 0
and j < len(board[0])
... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | def dfs(board, word, i, x, y, visited):
if i >= len(word):
return True
if (
x < 0
or x >= len(board)
or y < 0
or y >= len(board[0])
or visited[x][y]
or board[x][y] != word[i]
):
return False
visited[x][y] = True
a1 = dfs(board, word, i ... | FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUM... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Solution:
def wordBoggle(self, board, dictionary):
m, n = len(board), len(board[0])
output = []
def possible(i, j, m, n):
return i >= 0 and j >= 0 and i < m and j < n
def solver(t, board, word, inx, m, n):
if inx == len(word):
if word ... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FUNC_DEF RETURN VAR NUMBER VAR NUMBER VAR VAR VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIS... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Node:
def __init__(self):
self.link = dict()
self.end = False
class Trie:
def __init__(self):
self.root = Node()
def insert(self, word):
tem = self.root
for i in word:
if i not in tem.link:
tem.link[i] = Node()
tem = ... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL V... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Solution:
def wordBoggle(self, board, dictionary):
m, n = len(board), len(board[0])
trie = {}
stop = "#"
for word in dictionary:
node = trie
for ch in word:
if ch not in node:
node[ch] = {}
node = node... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR STRING FOR VAR VAR ASSIGN VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR DICT ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR NONE EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR ... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Solution:
def wordBoggle(self, board, dictionary):
res = []
for word in set(dictionary):
found = False
for r in range(len(board)):
if found:
break
for c in range(len(board[r])):
if has_word(board, ... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF ... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Solution:
def wordBoggle(self, board, dictionary):
n = len(board)
m = len(board[0])
l = []
s = {}
for word in dictionary:
if word in s:
continue
s[word] = 1
k = len(word)
f = 0
for i in range(n... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER ... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Trie:
def __init__(self):
self.root = Node()
def insert(self, st):
curr = self.root
for i in range(len(st)):
if curr.childs[ord(st[i]) - ord("A")] == None:
curr.childs[ord(st[i]) - ord("A")] = Node()
curr = curr.childs[ord(st[i]) - ord("A")... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NONE ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Solution:
def bfs(self, i, j, k, n, m, l, board, visited, word):
if k == l:
return True
dx = [0, 0, 1, -1, 1, 1, -1, -1]
dy = [1, -1, 0, 0, -1, 1, 1, -1]
for ind in range(8):
x, y = i + dx[ind], j + dy[ind]
if x >= 0 and x < n and y >= 0 and... | CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR V... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class TrieNode:
def __init__(self):
self.children = {}
self.isendWord = False
class Trie:
def __init__(self):
self.root = TrieNode()
def insert(self, word: str) -> None:
curr = self.root
for i in word:
if i not in curr.children:
curr.c... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF VAR ASSIGN VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER NONE CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL V... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Solution:
def wordBoggle(self, board, dictionary):
n, m = len(board), len(board[0])
answers = []
for word in dictionary:
for i in range(n):
for j in range(m):
if board[i][j] == word[0]:
visit = [([False] * m) for ... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR EXPR FUNC_C... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class TrieNode:
def __init__(self):
self.children = {}
self.isWord = False
def addWord(self, word):
curr = self
for c in word:
if c not in curr.children:
curr.children[c] = TrieNode()
curr = curr.children[c]
curr.isWord = True
c... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FU... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Solution:
def wordBoggle(self, board, dictionary):
dir = [[1, 0], [0, 1], [-1, 0], [0, -1], [1, 1], [-1, 1], [1, -1], [-1, -1]]
res = []
def solve(r, c, word, i):
if i == len(word):
res.append(word)
return
for j, k in dir:
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER ASSIGN VAR LIST FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP ... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | def backtracking(dictionary, board):
r, c = len(board), len(board[0])
res = set()
for word in dictionary:
for i in range(r):
state = False
for j in range(c):
if board[i][j] == word[0]:
vis = set()
vis.add((i, j))
... | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR VA... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Solution:
def wordBoggle(self, board, dicti):
def func(n, m, dicti, board, ind1, ind2, stri, ind, vis):
if ind == len(stri):
return True
if (
ind1 < 0
or ind2 < 0
or ind1 >= n
or ind2 >= m
... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR BIN... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Solution:
def wordBoggle(self, board, dictionary):
n = len(board)
m = len(board[0])
def solve(i, j, word, index, size):
count = 0
if i >= 0 and j >= 0 and i < n and j < m and word[index] == board[i][j]:
ch = board[i][j]
board[i]... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBE... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Solution:
def wordBoggle(self, board, dictionary):
def dfs(i, j, d):
if d == w:
return True
visited[i][j] = True
for k in range(8):
if (
0 <= i + a[k] < n
and 0 <= j + b[k] < m
... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF NUMBER BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BI... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Solution:
def wordBoggle(self, board, dictionary):
def dfs(i, j, k, word, vis):
vis[i][j] = True
if k == len(word):
return True
for x, y in directions:
if (
0 <= i + x < n
and 0 <= j + y < m
... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER FOR VAR VAR VAR IF NUMBER BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR ... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Solution:
def search(self, board, word, index, i, j):
n = len(board)
m = len(board[0])
if i < 0 or i > n - 1 or j < 0 or j > m - 1:
return False
if word[index] != board[i][j]:
return False
if index == len(word) - 1:
return True
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR VAR VAR VAR VAR RETURN NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR STRING ASSIGN VAR LIS... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Trie:
def __init__(self):
self.child = {}
self.e = 0
def add(self, word):
cur = self
for w in word:
if w not in cur.child:
cur.child[w] = Trie()
cur = cur.child[w]
cur.e = 1
class Solution:
def wordBoggle(self, board,... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL ... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Solution:
def wordBoggle(self, board, dictionary):
n = len(board)
m = len(board[0])
def dfs(board, s, i, j, idx):
if i < 0 or i >= n or j < 0 or j >= m:
return False
if s[idx] != board[i][j]:
return False
if idx == l... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR RETURN NUMBER IF VAR VAR VAR VAR VAR RETURN NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Node:
def __init__(self):
self.chi = {}
self.isla = False
class trie:
def __init__(self):
self.root = Node()
def add(self, word):
t = self.root
for val in word:
if t.chi.get(val) is None:
t.chi[val] = Node()
t = t.chi... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF IF... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Solution:
def dfs(self, board, m, n, word, coords, curind, visited):
if curind == len(word):
return True
visited.add(coords)
i, j = coords
if (
i - 1 >= 0
and j - 1 >= 0
and board[i - 1][j - 1] == word[curind]
and (i ... | CLASS_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Solution:
def wordBoggle(self, board, dictionary):
ROWS = len(board)
COLS = len(board[0])
def dfs(board, i, j, word, ind, visited):
if ind == len(word):
return True
if i < 0 or j < 0 or i >= ROWS or j >= COLS or visited[i][j]:
r... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Solution:
def wordBoggle(self, board, dictionary):
N = len(board)
M = len(board[0])
visited = [[(0) for _ in range(M)] for _ in range(N)]
res = []
words = set()
for k in range(len(dictionary)):
for i in range(N):
for j in range(M):
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR ... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | def dfs(board, r, c, word, wi, tu, visited):
a, b = tu
if wi == len(word) - 1:
return True
visited[a][b] = True
groups = [(-1, -1), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 1), (1, 0), (-1, 0)]
for g in groups:
i, j = g
if (
a + i >= 0
and a + i < r
... | FUNC_DEF ASSIGN VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class TrieNode:
def __init__(self):
self.child = {}
self.last = False
def insert(self, word):
curr = self
for i in word:
if i not in curr.child:
curr.child[i] = TrieNode()
curr = curr.child[i]
curr.last = True
class Solution:
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF IF VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR ... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class TrieNode:
def __init__(self):
self.children = {}
self.end = False
class Solution:
def __init__(self):
self.root = TrieNode()
def insert(self, word, root):
cur = root
for c in word:
if c not in cur.children:
cur.children[c] = Trie... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FUNC_DEF VAR VAR VAR VAR IF VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST LIST BIN_OP VAR NUMBER VAR L... |
Given a dictionary of words and an M x N board where every cell has one character. Find all possible different words from the dictionary that can be formed by a sequence of adjacent characters on the board. We can move to any of 8 adjacent characters, but a word should not have multiple instances of the same cell.
Exam... | class Solution:
dirs = [[1, 1], [1, 0], [1, -1], [0, -1], [-1, -1], [-1, 0], [-1, 1], [0, 1]]
def on_board(self, i, j, board):
return 0 <= i < len(board) and 0 <= j < len(board[0])
def removeFromDict(self, dictionary, i, ch):
new_dict = []
for w in dictionary:
if w[i] !... | CLASS_DEF ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER FUNC_DEF RETURN NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR VAR VAR IF BIN_OP... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.