description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Given a number K and string str of digits denoting a positive integer, build the largest number possible by performing swap operations on the digits of str at most K times.
Example 1:
Input:
K = 4
str = "1234567"
Output:
7654321
Explanation:
Three swaps can make the
input 1234567 to 7654321, swapping 1
with 7, 2 with 6... | class Solution:
def findMaximumNum(self, s, k):
ans = int(s)
s = list(s)
s = list(map(int, s))
def helper(start, s, k):
nonlocal ans
if k == 0 or start == len(s):
ta = int("".join(list(map(str, s))))
ans = max(ta, ans)
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN ASSIGN VAR LIST VAR ASSIGN VAR BI... |
Given a number K and string str of digits denoting a positive integer, build the largest number possible by performing swap operations on the digits of str at most K times.
Example 1:
Input:
K = 4
str = "1234567"
Output:
7654321
Explanation:
Three swaps can make the
input 1234567 to 7654321, swapping 1
with 7, 2 with 6... | class Solution:
def findMaximumNum(self, s, k):
mx = float("-inf")
def find(lst, k, ind):
nonlocal mx
if ind >= len(lst):
return
sm = 0
for i in lst:
sm = sm * 10 + i
if sm > mx:
mx = sm
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER RETURN ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBE... |
Given a number K and string str of digits denoting a positive integer, build the largest number possible by performing swap operations on the digits of str at most K times.
Example 1:
Input:
K = 4
str = "1234567"
Output:
7654321
Explanation:
Three swaps can make the
input 1234567 to 7654321, swapping 1
with 7, 2 with 6... | class Solution:
def findMaximumNum(self, s, k):
maxi = [float("-inf")]
arr = [char for char in s]
def swap(i, j, arr):
arr[i], arr[j] = arr[j], arr[i]
def helper(i, arr, k):
if k == 0 or i == len(arr):
return
maxChar = arr[i]
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FUNC_DEF IF VAR NUMBER VAR FUNC_CALL VAR VAR RETURN ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR IF... |
Given a number K and string str of digits denoting a positive integer, build the largest number possible by performing swap operations on the digits of str at most K times.
Example 1:
Input:
K = 4
str = "1234567"
Output:
7654321
Explanation:
Three swaps can make the
input 1234567 to 7654321, swapping 1
with 7, 2 with 6... | class Solution:
def findMaximumNum(self, s, k):
arr = list(s)
ans = [s]
def rec(i, c):
if i == len(s) or c == k:
ans[0] = max(ans[0], "".join(arr))
return
maxch = max([ord(ch) for ch in arr[i:]])
if ord(arr[i]) == maxch:
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL STRING VAR RETURN ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN FOR VAR... |
Given a number K and string str of digits denoting a positive integer, build the largest number possible by performing swap operations on the digits of str at most K times.
Example 1:
Input:
K = 4
str = "1234567"
Output:
7654321
Explanation:
Three swaps can make the
input 1234567 to 7654321, swapping 1
with 7, 2 with 6... | class Solution:
def findMaximumNum(self, s, k):
s = list(s)
self.ans = "0"
def swap(s, k, left, t):
if t == k or left >= len(s):
tmp = "".join(s)
if tmp > self.ans:
self.ans = tmp
if left < len(s) and t < k:
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FUNC_DEF IF VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR IF VAR VAR ASSIGN VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR ... |
Given a number K and string str of digits denoting a positive integer, build the largest number possible by performing swap operations on the digits of str at most K times.
Example 1:
Input:
K = 4
str = "1234567"
Output:
7654321
Explanation:
Three swaps can make the
input 1234567 to 7654321, swapping 1
with 7, 2 with 6... | class Solution:
def findMaximumNum(self, s, k):
st = list(s)
self.m = s
def solve(st, i, k):
if i >= len(st) or k == 0:
return
mxelm = st[i]
for j in range(i + 1, len(st)):
if int(st[j]) > int(mxelm):
m... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR VAR NUMBER RETURN ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR ... |
Given a number K and string str of digits denoting a positive integer, build the largest number possible by performing swap operations on the digits of str at most K times.
Example 1:
Input:
K = 4
str = "1234567"
Output:
7654321
Explanation:
Three swaps can make the
input 1234567 to 7654321, swapping 1
with 7, 2 with 6... | class Solution:
def findMaximumNum(self, s, k):
res = int(s)
n = len(s)
def swap(strg, i, j):
if i == j:
return strg
ith = strg[i]
jth = strg[j]
left = strg[0:i]
middle = strg[i + 1 : j]
right = strg[j ... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR RETURN VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR FUNC_DEF IF VAR VAR VAR... |
Given a number K and string str of digits denoting a positive integer, build the largest number possible by performing swap operations on the digits of str at most K times.
Example 1:
Input:
K = 4
str = "1234567"
Output:
7654321
Explanation:
Three swaps can make the
input 1234567 to 7654321, swapping 1
with 7, 2 with 6... | class Solution:
def findMaximumNum(self, s, k):
s = list(s)
maxStr = [""]
getMaximumNum(s, 0, 0, k, maxStr)
ansStr = ""
return maxStr[0]
def getGreatestNumber(s, idx):
minVal = 0
ans = 0
for i in range(idx, len(s)):
if ans <= int(s[i]):
ans ... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST STRING EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR ASSIGN VAR STRING RETURN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR RE... |
Given a number K and string str of digits denoting a positive integer, build the largest number possible by performing swap operations on the digits of str at most K times.
Example 1:
Input:
K = 4
str = "1234567"
Output:
7654321
Explanation:
Three swaps can make the
input 1234567 to 7654321, swapping 1
with 7, 2 with 6... | class Solution:
def helper(self, s, ans, i, k, n):
if k == 0 or i >= n:
return
s = list(s)
mx = max(s[i:])
if mx != s[i]:
k -= 1
for x in range(i, n):
if s[x] == mx:
s[i], s[x] = s[x], s[i]
ans[0] = max(ans[... | CLASS_DEF FUNC_DEF IF VAR NUMBER VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING ... |
Given a number K and string str of digits denoting a positive integer, build the largest number possible by performing swap operations on the digits of str at most K times.
Example 1:
Input:
K = 4
str = "1234567"
Output:
7654321
Explanation:
Three swaps can make the
input 1234567 to 7654321, swapping 1
with 7, 2 with 6... | class Solution:
def match(self, num, res):
for i in range(len(num)):
if res[i] > num[i]:
return
if res[i] < num[i]:
for i in range(len(num)):
res[i] = num[i]
return
def setDigit(self, num, index, res, k):
... | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR RETURN IF VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR RETURN FUNC_DEF IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR RETURN ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL... |
Given a number K and string str of digits denoting a positive integer, build the largest number possible by performing swap operations on the digits of str at most K times.
Example 1:
Input:
K = 4
str = "1234567"
Output:
7654321
Explanation:
Three swaps can make the
input 1234567 to 7654321, swapping 1
with 7, 2 with 6... | class Solution:
def findMaximumNum(self, s, k):
def eval_(s):
count = 0
for c in s:
if c == "0":
count += 1
else:
break
return eval(s[count:])
max_num = [eval_(s)]
def helper(s, st... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER RETURN ASSIGN VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR ... |
Given a number K and string str of digits denoting a positive integer, build the largest number possible by performing swap operations on the digits of str at most K times.
Example 1:
Input:
K = 4
str = "1234567"
Output:
7654321
Explanation:
Three swaps can make the
input 1234567 to 7654321, swapping 1
with 7, 2 with 6... | class Solution:
def findMaximumNum(self, s, k):
maxi = [int(s)]
idx = 0
chars = [char for char in s]
self.findMaxUtil(chars, idx, k, maxi)
return maxi[0]
def findMaxUtil(self, s, idx, k, maxi):
if idx > len(s) - 1 or k <= 0:
return
max_val = ... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR NUMBER FUNC_DEF IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER RETURN ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ... |
Given a number K and string str of digits denoting a positive integer, build the largest number possible by performing swap operations on the digits of str at most K times.
Example 1:
Input:
K = 4
str = "1234567"
Output:
7654321
Explanation:
Three swaps can make the
input 1234567 to 7654321, swapping 1
with 7, 2 with 6... | class Solution:
def helper(self, num, k, ans, ind):
n = len(num)
if k <= 0 or ind >= n - 1:
return
maxm = num[ind]
for i in range(ind + 1, n):
if int(maxm) < int(num[i]):
maxm = num[i]
if maxm != num[ind]:
k -= 1
fo... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER RETURN ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VA... |
Given a number K and string str of digits denoting a positive integer, build the largest number possible by performing swap operations on the digits of str at most K times.
Example 1:
Input:
K = 4
str = "1234567"
Output:
7654321
Explanation:
Three swaps can make the
input 1234567 to 7654321, swapping 1
with 7, 2 with 6... | class Solution:
def findMaximumNum(self, s, k):
n = len(s)
s = list(s)
i = 0
count = 0
def helper(s, count, i, k, n):
if count == k or i >= n - 1:
return "".join(s)
output = helper(s, count, i + 1, k, n)
maxl = s[i]
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR ... |
Given a number K and string str of digits denoting a positive integer, build the largest number possible by performing swap operations on the digits of str at most K times.
Example 1:
Input:
K = 4
str = "1234567"
Output:
7654321
Explanation:
Three swaps can make the
input 1234567 to 7654321, swapping 1
with 7, 2 with 6... | class Solution:
def findMaximumNum(self, s, k):
num = [int(x) for x in s]
res = [int(x) for x in s]
self.find(num, res, 0, k)
return "".join(str(x) for x in res)
def find(self, num, res, index, k):
if k == 0 or index == len(num) - 1:
self.match(num, res)
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR RETURN ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FU... |
Given a number K and string str of digits denoting a positive integer, build the largest number possible by performing swap operations on the digits of str at most K times.
Example 1:
Input:
K = 4
str = "1234567"
Output:
7654321
Explanation:
Three swaps can make the
input 1234567 to 7654321, swapping 1
with 7, 2 with 6... | class Solution:
def findMaximumNum(self, s, k):
def f(arr, start, k):
if k == 0:
return
if start == len(arr):
return
maximum = max(arr[start : len(arr)])
if arr[start] != maximum:
k -= 1
for i in ra... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER RETURN IF VAR FUNC_CALL VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ... |
Given a number K and string str of digits denoting a positive integer, build the largest number possible by performing swap operations on the digits of str at most K times.
Example 1:
Input:
K = 4
str = "1234567"
Output:
7654321
Explanation:
Three swaps can make the
input 1234567 to 7654321, swapping 1
with 7, 2 with 6... | class Solution:
def findMaximumNum(self, s, k):
def swap(arr, i, j):
arr[i], arr[j] = arr[j], arr[i]
def solve(idx, k, n):
if k == 0 or idx >= n:
return
rmax = arr[idx]
for j in range(idx + 1, n):
if arr[j] > rmax:
... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FUNC_DEF IF VAR NUMBER VAR VAR RETURN ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR EXPR F... |
Given a number K and string str of digits denoting a positive integer, build the largest number possible by performing swap operations on the digits of str at most K times.
Example 1:
Input:
K = 4
str = "1234567"
Output:
7654321
Explanation:
Three swaps can make the
input 1234567 to 7654321, swapping 1
with 7, 2 with 6... | class Solution:
def findMaximumNum(self, s, k):
string = [x for x in s]
maxn = [int(s)]
def maxi(maxn, string, index, k):
if k == 0 or index == len(string):
return
curr = string[index]
for i in range(index + 1, len(string)):
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER VAR FUNC_CALL VAR VAR RETURN ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL V... |
Given a number K and string str of digits denoting a positive integer, build the largest number possible by performing swap operations on the digits of str at most K times.
Example 1:
Input:
K = 4
str = "1234567"
Output:
7654321
Explanation:
Three swaps can make the
input 1234567 to 7654321, swapping 1
with 7, 2 with 6... | class Solution:
def findMaximumNum(self, s, k):
def fun(a, k, ans):
if a == []:
return int(ans)
maxi = max(a)
idx = a.index(maxi)
res = 0
if idx != 0 and k != 0:
for i in range(len(a)):
if a[i] ... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR LIST RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ... |
Given a number K and string str of digits denoting a positive integer, build the largest number possible by performing swap operations on the digits of str at most K times.
Example 1:
Input:
K = 4
str = "1234567"
Output:
7654321
Explanation:
Three swaps can make the
input 1234567 to 7654321, swapping 1
with 7, 2 with 6... | import sys
class Solution:
def swap(self, str, i, j):
s = list(str)
s[i], s[j] = s[j], s[i]
return "".join(s)
def findMaximumNum(self, s, k):
import sys
sys.setrecursionlimit(10000000)
result = [""]
self.findMax(0, s, k, result)
return result[... | IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR RETURN FUNC_CALL STRING VAR FUNC_DEF IMPORT EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST STRING EXPR FUNC_CALL VAR NUMBER VAR VAR VAR RETURN VAR NUMBER FUNC_DEF IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN ASSIGN VAR ... |
Given a number K and string str of digits denoting a positive integer, build the largest number possible by performing swap operations on the digits of str at most K times.
Example 1:
Input:
K = 4
str = "1234567"
Output:
7654321
Explanation:
Three swaps can make the
input 1234567 to 7654321, swapping 1
with 7, 2 with 6... | class Solution:
def findMaximumNum(self, s, k):
s = list(s)
n = len(s)
maximum = -float("inf")
def backtrack(k, idx):
nonlocal maximum
if k == 0 or idx == n:
return
curr_max = s[idx]
for j in range(idx + 1, n):
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FUNC_DEF IF VAR NUMBER VAR VAR RETURN ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER FOR VA... |
Given a number K and string str of digits denoting a positive integer, build the largest number possible by performing swap operations on the digits of str at most K times.
Example 1:
Input:
K = 4
str = "1234567"
Output:
7654321
Explanation:
Three swaps can make the
input 1234567 to 7654321, swapping 1
with 7, 2 with 6... | class Solution:
def findMaximumNum(self, s, k):
def backtrack(string, k, start):
nonlocal maxi
if k <= 0 or start >= len(string) - 1:
return
cur_digit = string[start]
for i in range(start + 1, len(string)):
if cur_digit < stri... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ... |
Given a number K and string str of digits denoting a positive integer, build the largest number possible by performing swap operations on the digits of str at most K times.
Example 1:
Input:
K = 4
str = "1234567"
Output:
7654321
Explanation:
Three swaps can make the
input 1234567 to 7654321, swapping 1
with 7, 2 with 6... | class Solution:
def findMaximumNum(self, s, k):
N = len(s)
input = list(s)
return self.permutateBetter(input, s, k, 0, N)
def permutateBetter(self, input, s, k, idx, N):
if k == 0 or idx == N:
return s
maxm = input[idx]
for v in range(idx + 1, N):
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR NUMBER VAR FUNC_DEF IF VAR NUMBER VAR VAR RETURN VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR I... |
Consider a grid of size $n \times n$. The rows are numbered top to bottom from $1$ to $n$, the columns are numbered left to right from $1$ to $n$.
The robot is positioned in a cell $(1, 1)$. It can perform two types of moves:
D — move one cell down;
R — move one cell right.
The robot is not allowed to move outside ... | Z = input
for _ in range(int(Z())):
m = int(Z())
s = Z()
n = len(s)
y = chr(150 - ord(s[0]))
x = (s + y).index(y)
print(
1 + n + (m - x) * m - (1 + s.count("D", x)) * (1 + s.count("R", x))
if x < n
else m
) | ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR... |
Consider a grid of size $n \times n$. The rows are numbered top to bottom from $1$ to $n$, the columns are numbered left to right from $1$ to $n$.
The robot is positioned in a cell $(1, 1)$. It can perform two types of moves:
D — move one cell down;
R — move one cell right.
The robot is not allowed to move outside ... | def main():
for _ in range(int(input())):
n = int(input())
s = input()
t = "".join([("D" if i == "R" else "R") for i in s])
poss = s.find("R")
post = t.find("R")
if s == "R" * len(s) or s == "D" * len(s):
print(n)
continue
res, cnta, cn... | FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR STRING STRING STRING VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR BIN_OP STRING FUNC_CALL VAR VAR VAR BIN_OP STRING FUNC_CALL VAR V... |
Consider a grid of size $n \times n$. The rows are numbered top to bottom from $1$ to $n$, the columns are numbered left to right from $1$ to $n$.
The robot is positioned in a cell $(1, 1)$. It can perform two types of moves:
D — move one cell down;
R — move one cell right.
The robot is not allowed to move outside ... | def calc(s, n):
ld = s.find("R")
res = ld * (n - 1)
y = 0
for i in range(len(s) - 1, ld - 1, -1):
if s[i] == "D":
res += y
else:
y += 1
return res
out = ""
for _ in range(int(input())):
n = int(input())
s = input()
if s.count(s[0]) == len(s):
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR VAR STRING VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR F... |
Consider a grid of size $n \times n$. The rows are numbered top to bottom from $1$ to $n$, the columns are numbered left to right from $1$ to $n$.
The robot is positioned in a cell $(1, 1)$. It can perform two types of moves:
D — move one cell down;
R — move one cell right.
The robot is not allowed to move outside ... | for _ in range(int(input())):
n = int(input())
s = input()
posX, posY = 0, 0
maxDown = [0]
maxRight = [0]
for c in s:
if c == "D":
posY += 1
maxDown[-1] += 1
maxRight.append(posX)
else:
posX += 1
maxDown.append(posY)
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER NUMBER I... |
Consider a grid of size $n \times n$. The rows are numbered top to bottom from $1$ to $n$, the columns are numbered left to right from $1$ to $n$.
The robot is positioned in a cell $(1, 1)$. It can perform two types of moves:
D — move one cell down;
R — move one cell right.
The robot is not allowed to move outside ... | def solve():
t = int(input())
for r in range(t):
n = int(input())
path = input()
cnt_r = path.count("R")
cnt_d = path.count("D")
if cnt_r == 0 or cnt_d == 0:
result = n
else:
move_r = n - cnt_r - 1
move_d = n - cnt_d - 1
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBE... |
Consider a grid of size $n \times n$. The rows are numbered top to bottom from $1$ to $n$, the columns are numbered left to right from $1$ to $n$.
The robot is positioned in a cell $(1, 1)$. It can perform two types of moves:
D — move one cell down;
R — move one cell right.
The robot is not allowed to move outside ... | import sys
def input():
return sys.stdin.readline()[:-1]
def readline():
return map(int, input().split())
def solve():
n = int(input())
s = input()
ans = len(s) + 1
r_cnt = s.count("R")
d_cnt = len(s) - r_cnt
width = r_cnt + 1
height = d_cnt + 1
if r_cnt and d_cnt:
... | IMPORT FUNC_DEF RETURN FUNC_CALL VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER A... |
Consider a grid of size $n \times n$. The rows are numbered top to bottom from $1$ to $n$, the columns are numbered left to right from $1$ to $n$.
The robot is positioned in a cell $(1, 1)$. It can perform two types of moves:
D — move one cell down;
R — move one cell right.
The robot is not allowed to move outside ... | def solve():
n = int(input())
s = input()
m = len(s)
flag = True
for i in range(1, m):
if s[i] != s[i - 1]:
flag = False
if flag:
return n
x, y = 1, 1
for c in s:
if c == "R":
y = y + 1
if c == "D":
x = x + 1
x, y = ... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR RETURN VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING ... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def solve(self, i, j, m, n, grid, word):
if grid[i][j] != word[0]:
return False
temp = [[1, 0], [0, 1], [-1, 0], [0, -1], [-1, 1], [1, -1], [1, 1], [-1, -1]]
r = i
c = j
for k in temp:
flag = True
i = r
j = c
... | CLASS_DEF FUNC_DEF IF VAR VAR VAR VAR NUMBER RETURN NUMBER 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 VAR ASSIGN VAR VAR FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASS... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def searchWord(self, grid, word):
def dfs(r, c, ind, d):
if r >= row or c >= col or r < 0 or c < 0 or grid[r][c] != word[ind]:
return False
if ind == len(word) - 1:
return True
return dfs(r + d[0], c + d[1], ind + 1, d)
... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR RETURN NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR L... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def helper(self, idx, dir, i, j, grid, word):
if not (0 <= i and i < len(grid) and 0 <= j and j < len(grid[0])):
return False
if word[idx] != grid[i][j]:
return False
if idx == len(word) - 1:
return True
if dir == 0:
re... | CLASS_DEF FUNC_DEF IF NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF VAR VAR VAR VAR VAR RETURN NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def helper(self, word, moves, i, j, grid):
if grid[i][j] != word[0]:
return False
for a, b in moves:
new_i, new_j = i + a, j + b
st = True
for k in range(1, len(word)):
if (
0 <= new_i < len(grid)
... | CLASS_DEF FUNC_DEF IF VAR VAR VAR VAR NUMBER RETURN NUMBER FOR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR RETURN... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def searchWord(self, grid, word):
res = []
for i in range(len(grid)):
for j in range(len(grid[0])):
if grid[i][j] == word[0]:
if self.find(i, j, grid, word, 1, "any"):
res.append((i, j))
return res
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR STRING VAR STRING BIN_OP VAR NUM... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def searchWord(self, grid, word):
m = len(grid)
n = len(grid[0])
indexes = [[(0) for j in range(n)] for i in range(m)]
d = [[1, 0], [-1, 0], [0, 1], [0, -1], [1, 1], [1, -1], [-1, 1], [-1, -1]]
for i in range(0, m):
for j in range(0, n):
... | 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 LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER FOR VA... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def search(self, i, j, grid, word, n, m):
if grid[i][j] != word[0]:
return False
drc = [[-1, 0], [-1, 1], [0, 1], [1, 1], [1, 0], [1, -1], [0, -1], [-1, -1]]
for xy in drc:
x = xy[0]
y = xy[1]
f = True
r = i + x
... | CLASS_DEF FUNC_DEF IF VAR VAR VAR VAR NUMBER RETURN NUMBER 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 FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP V... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def searchWord(self, grid, word):
def fun(i, j, k, s, f, l1, m1, n1):
if i < n and j < m and i >= 0 and j >= 0 and s + grid[i][j] == word:
return 1
if i < 0 or j < 0 or i >= n or j >= m:
return
ans = 0
if f == ... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER BIN_OP VAR VAR VAR VAR VAR RETURN NUMBER IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR RETURN ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER VAR VAR VAR VAR... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | def search2D(grid, row, col, word):
di = [[-1, 0], [1, 0], [1, 1], [1, -1], [-1, -1], [-1, 1], [0, 1], [0, -1]]
if grid[row][col] != word[0]:
return False
R = len(grid)
C = len(grid[0])
for x, y in di:
rd, cd = row + x, col + y
flag = True
for k in range(1, len(word))... | 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 IF VAR VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR VAR ASSIGN VAR VAR BIN_OP ... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def __init__(self):
self.R = None
self.C = None
self.dir = [
[-1, 0],
[1, 0],
[1, 1],
[1, -1],
[-1, -1],
[-1, 1],
[0, 1],
[0, -1],
]
def search2D(self, grid, row, col... | CLASS_DEF FUNC_DEF ASSIGN VAR NONE ASSIGN VAR NONE 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 VAR VAR VAR NUMBER RETURN NUMBER FOR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def perf(self, grid, word, i, j, n, m):
move = [[-1, 0], [-1, -1], [0, -1], [1, -1], [1, 0], [1, 1], [0, 1], [-1, 1]]
for k in range(8):
x = i + move[k][0]
y = j + move[k][1]
idx = 1
for p in range(1, len(word)):
if x <... | 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 FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def searchWord(self, grid, word):
n = len(grid)
m = len(grid[0])
def dfs(i, j, k, ind):
if ind == len(word):
return True
if i < 0 or j < 0 or i >= n or j >= m or grid[i][j] != word[ind]:
return False
return... | 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 VAR VAR RETURN NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER NUM... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def search(self, grid, row, col, word, r, c, dirc):
if grid[row][col] != word[0]:
return False
for x, y in dirc:
rd = row + x
cd = col + y
flag = True
for k in range(1, len(word)):
if 0 <= rd < r and 0 <= cd... | CLASS_DEF FUNC_DEF IF VAR VAR VAR VAR NUMBER RETURN NUMBER FOR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF NUMBER VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR RETURN NUMBER RETURN NUMBER FUNC_D... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def searchWord(self, grid, word):
ans = []
r = len(grid)
c = len(grid[0])
def recurs(c, starti, startj, direct, i, j, ans):
if c == "":
if [starti, startj] not in ans:
ans.append([starti, startj])
retur... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR STRING IF LIST VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR RETURN IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER RETURN IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR ... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def searchWord(self, M, w):
R, C = len(M), len(M[0])
ans = []
for r in range(R):
for c in range(C):
if M[r][c] == w[0] and expand(r, c, R, C, M, w):
ans.append([r, c])
return ans
def expand(sr, sc, R, C, M, w):
fo... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR N... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | def dfs(row, col, word, m, n, grid, direction):
if len(word) == 0:
return True
x, y = direction
if (
row + x >= 0
and row + x < m
and col + y >= 0
and col + y < n
and grid[row + x][col + y] == word[0]
):
if dfs(row + x, col + y, word[1:], m, n, gri... | FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER CLASS_DEF FUNC_DEF... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def __init__(self):
self.ans = {}
def searchWord(self, grid, word):
ans = []
n = len(grid)
m = len(grid[0])
dirs = [(-1, 0), (0, -1), (-1, -1), (-1, 1), (1, -1), (1, 0), (1, 1), (0, 1)]
def is_possible(grid, word, i, j, dirs):
n = le... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def solve(self, i, j, k, n, m, l, dx, dy, grid, visited, word):
if visited[i][j]:
return False
visited[i][j] = 1
x, y = dx + i, dy + j
if x >= 0 and x < n and y >= 0 and y < m:
if k + 1 == l - 1 and word[k + 1] == grid[x][y]:
r... | CLASS_DEF FUNC_DEF IF VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR RETURN NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR IF FUNC_CALL V... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | def search(grid, word, row, col):
y = [0, -1, -1, -1, 0, 1, 1, 1]
x = [1, 1, 0, -1, -1, -1, 0, 1]
for i in range(8):
X = x[i] + row
Y = y[i] + col
k = 1
while (
X >= 0
and X < len(grid)
and Y >= 0
and Y < len(grid[0])
... | FUNC_DEF 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 BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_C... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def searchWord(self, grid, word):
n = len(grid)
m = len(grid[0])
l = len(word)
output = []
for i in range(n):
for j in range(m):
if i >= l - 1:
candi = ""
for k in range(l):
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR IF BI... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def __compare_direction_substring(
self, i, j, k, offset_row, offset_col, n, grid, word
):
while k < n:
if grid[i][j] != word[k]:
return False
i += offset_row
j += offset_col
k += 1
return True
def sear... | CLASS_DEF FUNC_DEF WHILE VAR VAR IF VAR VAR VAR VAR VAR RETURN NUMBER VAR VAR VAR VAR VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMB... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def __init__(self):
self.ans = []
def dfs(self, grid, i, j, n, m, curr_word, word, start_i, start_j, dir):
if curr_word == len(word):
if (start_i, start_j) not in self.ans:
self.ans.append((start_i, start_j))
return True
if i >= n... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR RETURN ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR STRING IF VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR ... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def searchWord(self, grid, word):
def count(row, col):
if grid[row][col] != word[0]:
return False
for x, y in rcmat:
rd = row + x
cl = col + y
flag = True
for k in range(1, len(word)):
... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR VAR VAR NUMBER RETURN NUMBER FOR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF NUMBER VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUM... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def searchWord(self, grid, word):
def check(i, j, x, y, ll, n, grid, word, r, c):
if i < 0 or i >= r or j < 0 or j >= c:
return False
if ll == n - 1:
if word[ll] == grid[i][j]:
return True
return Fa... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR RETURN NUMBER IF VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER IF VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VA... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def internal_search(self, idx, word, grid, row, col, row_max, col_max):
if row < 0 or row > row_max or col < 0 or col > col_max:
return False
if grid[row][col] != word[0]:
return False
dxy = [[0, 1], [0, -1], [1, 0], [-1, 0], [1, 1], [1, -1], [-1, 1],... | CLASS_DEF FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR RETURN NUMBER IF VAR VAR VAR VAR NUMBER RETURN NUMBER 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 FOR VAR VAR VAR ASSIGN VAR BIN_OP VAR ... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def searchWord(self, grid, word):
def valid(i, j):
if 0 <= i < len(grid) and 0 <= j < len(grid[0]):
return True
return False
x = [0, 0, -1, -1, -1, 1, 1, 1]
y = [-1, 1, -1, 0, 1, -1, 0, 1]
def soln(i, j, dirn, m):
... | CLASS_DEF FUNC_DEF FUNC_DEF IF NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF V... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def searchWord(self, grid, word):
def found(i, j, d):
wl = len(word)
for k in range(wl):
if grid[i][j] != word[k]:
return False
else:
i, j = i + d[0], j + d[1]
if i < 0 or i ... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR RETURN VAR BIN_OP VAR NUMBER NUMBER NUMBER RETURN NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def searchWord(self, grid, word):
def dfs(i, r, c, move):
if (
r < 0
or r >= len(grid)
or c < 0
or c >= len(grid[0])
or word[i] != grid[r][c]
):
return False
... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR VAR RETURN NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR VAR RETURN NUMBER IF VAR STRING RETURN FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR STRING FUNC_CALL VAR BIN_OP VAR NU... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def searchWord(self, grid, word):
n, m, l, x = len(grid), len(grid[0]), len(word), []
def right(i, j, k, n, m, l):
if k == l:
return True
if j >= m or grid[i][j] != word[k]:
return False
return right(i, j + 1, k + ... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR LIST FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR VAR VAR VAR VAR RETURN NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER VAR VAR VAR ... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def searchWord(self, grid, word):
directions = [
[1, 0],
[1, 1],
[0, 1],
[-1, 1],
[-1, 0],
[-1, -1],
[0, -1],
[1, -1],
]
if not grid or not word:
return []
n =... | 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 IF VAR VAR RETURN LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER VAR VA... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def findWord(self, mat, target, dir, i, j, curind):
if i < 0 or j < 0 or i >= len(mat) or j >= len(mat[0]):
return 0
curchar = mat[i][j]
if target[curind] != curchar:
return 0
if curind == len(target) - 1:
return 1
count = ... | CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR VAR RETURN NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER IF VAR NUMBER RETURN FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBE... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def searchWord(self, grid, word):
r = len(grid)
c = len(grid[0])
res = []
l = len(word)
for i in range(len(grid)):
for j in range(len(grid[i])):
if grid[i][j] == word[0]:
h_r = grid[i][j : j + l]
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL STRING VAR IF BIN_OP B... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def searchWord(self, board, word):
def help(board, w, r, c):
x = [
[-1, 0],
[1, 0],
[-1, 0],
[0, 1],
[0, -1],
[-1, -1],
[-1, 1],
[1, -1],
... | CLASS_DEF FUNC_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 LIST NUMBER NUMBER IF VAR VAR VAR VAR NUMBER RETURN NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VA... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | direction = [[-1, 0], [1, 0], [1, 1], [1, -1], [-1, -1], [-1, 1], [0, 1], [0, -1]]
class Solution:
def searchWord(self, grid, word):
ans = []
for i in range(len(grid)):
for j in range(len(grid[0])):
if self.findword(grid, i, j, word):
ans.append((i,... | 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 CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR V... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def rec(self, i, j, grid, m, n, word, l, vis):
paths = [[-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 1], [1, -1], [1, 0], [1, 1]]
for kk in paths:
k = 0
ii, jj = i, j
while 0 <= ii < m and 0 <= jj < n:
if k == l:
re... | 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 FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR WHILE NUMBER VAR VAR NUMBER VAR VAR IF VAR VAR RETURN NUMBER IF VAR VAR VAR VAR ... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def find(self, p, q, grid, word, r, n, m):
di = [[0, -1], [0, 1], [-1, 0], [-1, -1], [-1, 1], [1, 0], [1, -1], [1, 1]]
for i in range(8):
c = 0
h = p
h1 = q
while (
h < n
and h1 < m
and h... | 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 FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR ... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def searchWord(self, grid, word):
def helper(i, j, k, n, m, l, x, y):
if k == l:
return True
if i < 0 or j < 0 or j >= m or i >= n or grid[i][j] != word[k]:
return False
return helper(i + x, j + y, k + 1, n, m, l, x, y)
... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR RETURN NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def isValid(self, x, y, n, m):
if x >= 0 and y >= 0 and x < n and y < m:
return True
return False
def solve(self, mat, word, i, j, n, m, X, Y):
for x in range(8):
nx = i + X[x]
ny = j + Y[x]
flag = True
for w i... | CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def solve(self, i, j, grid, word, x, temp):
if x == len(word):
return True
if (
(temp == "top" or temp == "first")
and i + 1 < len(grid)
and grid[i + 1][j] == word[x]
):
if self.solve(i + 1, j, grid, word, x + 1, "t... | CLASS_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR STRING VAR STRING BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER STRING RETURN NUMBER IF VAR STRING VAR STRING BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR V... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def searchWord(self, grid, word):
result = []
for i in range(0, len(grid)):
for j in range(0, len(grid[0])):
if grid[i][j] == word[0] and self.dfs(i, j, 0, word, grid, 0):
result.append([i, j])
return result
def dfs(self, ... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR RETURN VAR FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN NUMBER IF VAR NUMBER VAR NUMBE... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def solve(self, i, j, grid, word, idx, dirx, diry):
if idx == len(word):
return True
else:
found = False
if (
0 <= i + dirx < len(grid)
and 0 <= j + diry < len(grid[0])
and grid[i + dirx][j + diry] =... | CLASS_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR NUMBER IF NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def searchWord(self, grid, word):
ans = []
n = len(grid)
m = len(grid[0])
def find(i, j, k, dr, word, grid):
if k == len(word):
return True
if (
i < 0
or i >= len(grid)
or j < 0
... | 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 FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR VAR RETURN NUMBER IF VAR NUMBER VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def searchWord(self, grid, word):
def possible(word, grid, i, j, d):
row = [0, 1, 0, -1, 1, 1, -1, -1]
col = [1, 0, -1, 0, 1, -1, -1, 1]
if d == 0:
right = len(grid[0]) - j - 1 >= len(word) - 1
if not right:
... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR RETURN IF VAR NUMBER ASSIGN VAR BI... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def searchWord(self, grid, word):
dx = [1, 1, 0, -1, -1, -1, 0, 1]
dy = [0, 1, 1, 1, 0, -1, -1, -1]
res = []
for i in range(len(grid)):
for j in range(len(grid[0])):
for k in range(8):
x = i
y = j
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def searchWord(self, grid, word):
n = len(grid)
m = len(grid[0])
d = [[-1, 0], [1, 0], [1, 1], [1, -1], [-1, -1], [-1, 1], [0, 1], [0, -1]]
def solve(grid, row, col, w, n, m):
if w[0] != grid[row][col]:
return False
for di in ... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER 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 VAR VAR VAR RETURN NUMBER FOR VAR VAR ASSIGN ... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def searchWord(self, grid, word):
ans = set()
dir = [[-1, -1], [-1, 1], [1, -1], [1, 1], [-1, 0], [0, -1], [0, 1], [1, 0]]
def dfs(i, j, ind, d):
if ind == len(word):
return True
if i < 0 or j < 0 or i >= len(grid) or j >= len(grid[0]... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL 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 FUNC_CALL VAR VAR RETURN NUMBER IF VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def searchWord(self, grid, word):
row = len(grid)
col = len(grid[0])
directory = [
[-1, -1],
[-1, 0],
[-1, 1],
[0, -1],
[0, 1],
[1, -1],
[1, 0],
[1, 1],
]
output =... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER 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 FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def check(self, grid, word, n, m, n_word, i, j):
y = i
x = j
index = 0
while y >= 0 and grid[y][x] == word[index]:
y -= 1
index += 1
if index == n_word:
return True
y = i
x = j
index = 0
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR VAR ASS... |
Given a 2D grid of n*m of characters and a word, find all occurrences of given word in grid. A word can be matched in all 8 directions at any point. Word is said to be found in a direction if all characters match in this direction (not in zig-zag form). The 8 directions are, horizontally left, horizontally right, verti... | class Solution:
def searchWord(self, grid, word):
n, m, l, x = len(grid), len(grid[0]), len(word), []
def helper(i, j, k, n, m, l, di, dj):
if k == l:
return True
if j < 0 or i < 0 or j >= m or i >= n or grid[i][j] != word[k]:
return False
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR LIST FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR RETURN NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR LIS... |
Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.
Each number in candidates may only be used once in the combination.
Note:
All numbers (including target) will be positive integers.
... | class Solution:
def combinationSum2(self, candidates, target):
result = []
def combinationSumRecu(self, candidates, target, start, intermediate, result):
if target == 0:
result.append(list(intermediate))
while start < len(candidates) and candidates[start] <=... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR WHILE VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_O... |
Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.
Each number in candidates may only be used once in the combination.
Note:
All numbers (including target) will be positive integers.
... | class Solution:
def find(self, candidates, result, current, target, pos, num, current_num):
if target == 0:
temp = current[:]
result.append(temp)
else:
for i in range(pos, len(candidates)):
n = str(candidates[i])
if candidates[i] >... | CLASS_DEF FUNC_DEF IF VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CA... |
Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.
Each number in candidates may only be used once in the combination.
Note:
All numbers (including target) will be positive integers.
... | class Solution:
def combinationSum2(self, candidates, target):
def dfs(i, val, path):
while i < len(candidates):
num = candidates[i]
val_ = val + num
path_ = path + [num]
if val_ > target:
return
... | CLASS_DEF FUNC_DEF FUNC_DEF WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR LIST VAR IF VAR VAR RETURN IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER V... |
Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.
Each number in candidates may only be used once in the combination.
Note:
All numbers (including target) will be positive integers.
... | class Solution:
def combinationSum2(self, candidates, target):
dp = [None] + [set() for i in range(target)]
candidates.sort()
for i in candidates:
if i > target:
break
for j in range(target - i, 0, -1):
dp[i + j] |= {(_ + (i,)) for _ i... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NONE FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR NUMBER |
Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.
Each number in candidates may only be used once in the combination.
Note:
All numbers (including target) will be positive integers.
... | class Solution:
def combinationSum2(self, candidates, target):
def backtracing(nums, target, idx, path, ret):
if not target:
if path not in ret:
ret.append(path)
for i in range(idx, len(nums)):
if nums[i] > target:
... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR NUMBER LIST VAR RETURN VAR |
Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.
Each number in candidates may only be used once in the combination.
Note:
All numbers (including target) will be positive integers.
... | class Solution:
def combinationSum2(self, candidates, target):
sortedCandidates = sorted(candidates)
if len(candidates) == 0 or target < sortedCandidates[0]:
return []
if target == sortedCandidates[0]:
return [[sortedCandidates[0]]]
resultWith0 = self.combina... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER RETURN LIST IF VAR VAR NUMBER RETURN LIST LIST VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ... |
Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.
Each number in candidates may only be used once in the combination.
Note:
All numbers (including target) will be positive integers.
... | class Solution:
def combinationSum2(self, candidates, target):
res = []
candidates.sort()
self.dfs(candidates, target, 0, [], res)
return res
def dfs(self, nums, target, index, path, res):
if target < 0:
return
if target == 0:
res.append(... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR NUMBER LIST VAR RETURN VAR FUNC_DEF IF VAR NUMBER RETURN IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR ... |
Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.
Each number in candidates may only be used once in the combination.
Note:
All numbers (including target) will be positive integers.
... | class Solution(object):
def combinationSum2(self, candidates, target):
result = []
temp = []
candidates.sort(reverse=True)
self.util(candidates, target, result, temp)
return result
def util(self, nums, target, result, temp):
for i in range(len(nums)):
... | CLASS_DEF VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR LIST VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BI... |
Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.
Each number in candidates may only be used once in the combination.
Note:
All numbers (including target) will be positive integers.
... | class Solution:
def combinationSum2(self, candidates, target):
def produce(nums, target, current, output):
if target == 0:
output.append(list(current))
return
for i, n in enumerate(nums):
if n > target:
continue
... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR EXPR FUN... |
Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.
Each number in candidates may only be used once in the combination.
Note:
All numbers (including target) will be positive integers.
... | class Solution:
def combinationSum2(self, candidates, target):
def combination(candidates, k, target, res, result):
for i in range(k, len(candidates)):
if target == candidates[i]:
temp = [j for j in res]
temp.append(candidates[i])
... | CLASS_DEF FUNC_DEF FUNC_DEF FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN IF VAR VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR EXPR F... |
Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.
Each number in candidates may only be used once in the combination.
Note:
All numbers (including target) will be positive integers.
... | class Solution:
def combinationSum2(self, candidates, target):
def helper(L, target, path, ans):
if target == 0:
ans.append(path)
return
for i in range(len(L)):
if L[i] > target:
return
if i > 0 and... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR RETURN IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR LIST VAR VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR FUNC_CALL VAR VAR V... |
Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.
Each number in candidates may only be used once in the combination.
Note:
All numbers (including target) will be positive integers.
... | class Solution:
def combinationSum2(self, candidates, target):
if not candidates:
return []
result = []
candidates.sort()
self.dfs(result, [], 0, target, candidates)
return result
def dfs(self, result, combin, start, target, candidates):
if target ==... | CLASS_DEF FUNC_DEF IF VAR RETURN LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR LIST NUMBER VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CA... |
Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.
Each number in candidates may only be used once in the combination.
Note:
All numbers (including target) will be positive integers.
... | class Solution:
def combinationSum2(self, nums, target):
def dfs(a, i, target):
for j in range(i, len(nums)):
if target <= nums[j]:
if target == nums[j]:
ans.append(a + [nums[j]])
break
if i == j or... | CLASS_DEF FUNC_DEF FUNC_DEF FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR LIST VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR LIST VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR EXPR 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 wh... | class Solution:
def minRepeats(self, A, B):
count = 0
b = 0
new = A
while len(new) <= len(B) + len(A):
if B in new:
return count + 1
count += 1
new = new + A
return -1 | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR RETURN BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR 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 wh... | class Solution:
def minRepeats(self, A, B):
la = len(A)
lb = len(B)
min_repeat = 1
repeated_a = A
while len(repeated_a) <= la + lb:
if B in repeated_a:
return min_repeat
repeated_a += A
min_repeat += 1
return -1 | 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 BIN_OP VAR VAR IF VAR VAR RETURN VAR 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 wh... | class Solution:
def minRepeats(self, A, B):
n = len(B) // len(A)
if B in A * n:
return n
if B in A * (n + 1):
return n + 1
if B in A * (n + 2):
return n + 2
return -1 | CLASS_DEF FUNC_DEF ASSIGN 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 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 wh... | class Solution:
def minRepeats(self, A, B):
temp_A = ""
m = len(B)
n = len(A)
repeat_times = m // n + 2
if B not in A * repeat_times:
return -1
cnt = 0
while True:
temp_A = temp_A + A
cnt += 1
if B in temp_A:
... | CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR RETURN NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR 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 wh... | class Solution:
def minRepeats(self, A, B):
re = len(B) // len(A)
stri = ""
stri += A * re
if B in stri:
return re
else:
stri += A
if B in stri:
return re + 1
else:
return -1 | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR BIN_OP VAR VAR IF VAR VAR RETURN VAR VAR VAR 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 wh... | class Solution:
def minRepeats(self, A, B):
a = ""
repeat = 0
while len(a) < len(A) + len(B):
a += A
repeat += 1
if B in a:
return repeat
return -1 | CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR 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 wh... | class Solution:
def minRepeats(self, a, b):
if b in a:
return 1
s = a
count = 1
while len(s) < 2 * len(b):
if b in s:
return count
else:
s += a
count += 1
else:
return -1 | CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR IF VAR VAR RETURN VAR 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 wh... | class Solution:
def minRepeats(self, A, B):
matchstr = ""
repeat = 0
for e in set(A):
if e not in B:
return -1
while len(matchstr) <= len(B):
matchstr += A
repeat += 1
if B in matchstr:
return repeat
... | CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR RETURN VAR RETURN NUMBER |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.