description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Given a maze with N cells. Each cell may have multiple entry points but not more than one exit(i.e entry/exit points are unidirectional doors like valves).
You are given an array Edge[] of N integers, where Edge[i] contains the cell number that can be reached from of cell i in one step. Edge[i] is -1 if the ith cell do... | import sys
sys.setrecursionlimit(10**6)
class Solution:
def largestSumCycle(self, N, Edge):
dp = [(0) for i in range(N)]
cx = [(0) for i in range(N)]
solve = [-1]
def dfs(n, s, c):
cx[n] = c
dp[n] = s
s += n
if Edge[n] != -1:
... | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR V... |
Given a maze with N cells. Each cell may have multiple entry points but not more than one exit(i.e entry/exit points are unidirectional doors like valves).
You are given an array Edge[] of N integers, where Edge[i] contains the cell number that can be reached from of cell i in one step. Edge[i] is -1 if the ith cell do... | class Solution:
def largestSumCycle(self, N, Edge):
done = set()
ans = -1
for i in range(N):
if i in done:
continue
path = [i]
d2 = set([i])
x = i
cycle = False
done.add(i)
while True:
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR FUNC_CALL VAR LIST VAR ASSIGN VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EX... |
Given a maze with N cells. Each cell may have multiple entry points but not more than one exit(i.e entry/exit points are unidirectional doors like valves).
You are given an array Edge[] of N integers, where Edge[i] contains the cell number that can be reached from of cell i in one step. Edge[i] is -1 if the ith cell do... | class Solution:
def largestSumCycle(self, N, Edge):
cells = []
result = 0
covered = {0}
for i in range(N):
cells = [i]
index = i
while True:
if Edge[index] == -1 or Edge[index] < i:
break
elif Ed... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR VAR WHILE NUMBER IF VAR VAR NUMBER VAR VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR ... |
Given a maze with N cells. Each cell may have multiple entry points but not more than one exit(i.e entry/exit points are unidirectional doors like valves).
You are given an array Edge[] of N integers, where Edge[i] contains the cell number that can be reached from of cell i in one step. Edge[i] is -1 if the ith cell do... | class Solution:
def largestSumCycle(self, N, Edge):
visited = [(0) for i in range(N)]
ans = -1
s = 0
cur = 0
cycle = False
for i in range(N):
cur = i
s = 0
cycle = 0
while cur != -1:
if visited[cur] != 0... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR ... |
Given a maze with N cells. Each cell may have multiple entry points but not more than one exit(i.e entry/exit points are unidirectional doors like valves).
You are given an array Edge[] of N integers, where Edge[i] contains the cell number that can be reached from of cell i in one step. Edge[i] is -1 if the ith cell do... | class Solution:
def largestSumCycle(self, N, Edge):
visited = [(False) for i in range(N)]
ans = -1
for i in range(N):
if not visited[i] and Edge[i] != -1:
sum, v = i, Edge[i]
result = {}
while Edge[v] != -1 and not visited[v]:
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR DICT WHILE VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR... |
Given a maze with N cells. Each cell may have multiple entry points but not more than one exit(i.e entry/exit points are unidirectional doors like valves).
You are given an array Edge[] of N integers, where Edge[i] contains the cell number that can be reached from of cell i in one step. Edge[i] is -1 if the ith cell do... | class Solution:
def largestSumCycle(self, N, Edge):
seen = {}
for i, e in enumerate(Edge):
if e == -1:
seen[i] = -1
else:
seen[i] = 0
def dfs(node):
cycle_sum = 0
cycle_set = {}
while node != -1 and... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT WHILE VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR ASSIGN VAR VAR LIST VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER FOR VAR VAR FUNC_... |
Given a maze with N cells. Each cell may have multiple entry points but not more than one exit(i.e entry/exit points are unidirectional doors like valves).
You are given an array Edge[] of N integers, where Edge[i] contains the cell number that can be reached from of cell i in one step. Edge[i] is -1 if the ith cell do... | import sys
sys.setrecursionlimit(150000)
class Solution:
def largestSumCycle(self, N, Edge):
visited = [False] * N
dp_sum = [-1] * N
ans = [-1]
def dfs_u(src, cur_sum):
if dp_sum[src] != -1:
ans[0] = max(ans[0], cur_sum - dp_sum[src] + src)
... | IMPORT EXPR FUNC_CALL VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST NUMBER FUNC_DEF IF VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR RETURN IF VAR VAR RETURN ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR ... |
Given a maze with N cells. Each cell may have multiple entry points but not more than one exit(i.e entry/exit points are unidirectional doors like valves).
You are given an array Edge[] of N integers, where Edge[i] contains the cell number that can be reached from of cell i in one step. Edge[i] is -1 if the ith cell do... | import sys
sys.setrecursionlimit(1000000)
class Solution:
def __init__(self):
self.answer = -1
def searchCycle(self, current_node, visit_list, cycle_visit_list, edge):
visit_list[current_node] = True
cycle_visit_list[current_node] = True
adj_node = edge[current_node]
... | IMPORT EXPR FUNC_CALL VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR ... |
Given a maze with N cells. Each cell may have multiple entry points but not more than one exit(i.e entry/exit points are unidirectional doors like valves).
You are given an array Edge[] of N integers, where Edge[i] contains the cell number that can be reached from of cell i in one step. Edge[i] is -1 if the ith cell do... | class Solution:
def solve(self, p, Edge):
su = p
s = p
p = Edge[s]
while p != s:
su += p
p = Edge[p]
return su
def largestSumCycle(self, N, Edge):
visited = [(False) for i in range(N)]
answer = 0
for i in range(len(Edge)):... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR DICT ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR ASS... |
Given a maze with N cells. Each cell may have multiple entry points but not more than one exit(i.e entry/exit points are unidirectional doors like valves).
You are given an array Edge[] of N integers, where Edge[i] contains the cell number that can be reached from of cell i in one step. Edge[i] is -1 if the ith cell do... | class Solution:
def largestSumCycle(self, N, Edge):
nodes = []
visited = set()
for node in range(N):
cycle = set()
while node != -1 and not node in visited:
cycle.add(node)
node = Edge[node]
if node in cycle:
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR WHILE VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR... |
Given a maze with N cells. Each cell may have multiple entry points but not more than one exit(i.e entry/exit points are unidirectional doors like valves).
You are given an array Edge[] of N integers, where Edge[i] contains the cell number that can be reached from of cell i in one step. Edge[i] is -1 if the ith cell do... | class Solution:
def largestSumCycle(self, N, Edge):
ans = -1
vis = [-1] * N
S = [0] * N
label = 0
for i, x in enumerate(Edge):
j = i
s = 0
while vis[j] == -1:
vis[j] = label
S[j] = s
s += j
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR IF NUMBER VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CA... |
Given a maze with N cells. Each cell may have multiple entry points but not more than one exit(i.e entry/exit points are unidirectional doors like valves).
You are given an array Edge[] of N integers, where Edge[i] contains the cell number that can be reached from of cell i in one step. Edge[i] is -1 if the ith cell do... | import sys
sys.setrecursionlimit(10**6)
class Solution:
def dfs(self, graph, visited, u):
if visited[u] == 2:
return -1
elif visited[u] == 1:
res, cur = u, u
while graph[cur] != u:
cur = graph[cur]
res += cur
return ... | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER CLASS_DEF FUNC_DEF IF VAR VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR WHILE VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR RETURN VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER RETURN VAR ASSIGN VAR ... |
Given a maze with N cells. Each cell may have multiple entry points but not more than one exit(i.e entry/exit points are unidirectional doors like valves).
You are given an array Edge[] of N integers, where Edge[i] contains the cell number that can be reached from of cell i in one step. Edge[i] is -1 if the ith cell do... | class Solution:
def largestSumCycle(self, N, Edge):
check = [0] * N
ans = -1
for i in range(N):
if Edge[i] != -1 and check[i] == 0:
check[i] = 1
a = {i: 0}
s = i
curr = Edge[i]
while curr not in a an... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR DICT VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER IF ... |
Given a maze with N cells. Each cell may have multiple entry points but not more than one exit(i.e entry/exit points are unidirectional doors like valves).
You are given an array Edge[] of N integers, where Edge[i] contains the cell number that can be reached from of cell i in one step. Edge[i] is -1 if the ith cell do... | import sys
sys.setrecursionlimit(10**6)
class Solution:
def dfs(self, node, p=-1):
self.vis[node] = 1
self.par[node] = p
self.tmp.append(node)
for i in self.v[node]:
if self.vis[i] == 0:
z = self.dfs(i, node)
if z != -1:
... | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER CLASS_DEF FUNC_DEF NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN VAR IF VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR RETURN... |
Given a string, the task is to find whether it contains an additive sequence or not. A string contains an additive sequence if its digits can make a sequence of numbers in which every number is addition of previous two numbers. You are required to complete the function which returns true if the string is a valid sequen... | def isValid(first, second, others):
if len(first) > 1 and first[0] == "0" or len(second) > 1 and second[0] == "0":
return 0
sum_str = str(int(first) + int(second))
if sum_str == others:
return 1
elif others.startswith(sum_str):
return isValid(second, sum_str, others[len(sum_str) ... | FUNC_DEF IF FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL... |
Given a string, the task is to find whether it contains an additive sequence or not. A string contains an additive sequence if its digits can make a sequence of numbers in which every number is addition of previous two numbers. You are required to complete the function which returns true if the string is a valid sequen... | def solve(a, b, s, k, n, start=0):
if k == n and start > 0:
return 1
for i in range(1, n):
if k + i > n:
break
c = int(s[k : k + i])
if c == a + b:
return solve(b, c, s, k + i, n, start + 1)
elif c > a + b:
return 0
return 0
def i... | FUNC_DEF NUMBER IF VAR VAR VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUN... |
Given a string, the task is to find whether it contains an additive sequence or not. A string contains an additive sequence if its digits can make a sequence of numbers in which every number is addition of previous two numbers. You are required to complete the function which returns true if the string is a valid sequen... | def find_seq(n1, n2, s, found):
if s == "" and found:
return True
n3 = str(n1 + n2)
idx = min(len(s), len(n3))
if s[:idx] == n3:
return find_seq(n2, int(n3), s[idx:], True)
return False
def isAdditiveSequence(num):
for i in range(1, len(num) - 1):
n1 = int(num[:i])
... | FUNC_DEF IF VAR STRING VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL ... |
Given a string, the task is to find whether it contains an additive sequence or not. A string contains an additive sequence if its digits can make a sequence of numbers in which every number is addition of previous two numbers. You are required to complete the function which returns true if the string is a valid sequen... | def isAdditiveSequence(num):
for i in range(len(num) // 2):
a = int(num[: i + 1])
for j in range(i + 1, len(num) - i - 1):
b = int(num[i + 1 : j + 1])
summ = str(a + b)
idx, flag = 0, True
for k in range(j + 1, len(num)):
if idx == len(... | FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER ... |
Given a string, the task is to find whether it contains an additive sequence or not. A string contains an additive sequence if its digits can make a sequence of numbers in which every number is addition of previous two numbers. You are required to complete the function which returns true if the string is a valid sequen... | def isAdditiveSequence(num):
def ne(val, k, s):
for i in range(k + 1, len(s) + 1):
if int(s[k:i]) == val:
return i
return -1
def ad(prev1, prev2, s):
if s == "":
return 1
if prev1 == 0:
ret = False
for i in range(1... | FUNC_DEF FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR RETURN NUMBER FUNC_DEF IF VAR STRING RETURN NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BI... |
Given a string, the task is to find whether it contains an additive sequence or not. A string contains an additive sequence if its digits can make a sequence of numbers in which every number is addition of previous two numbers. You are required to complete the function which returns true if the string is a valid sequen... | def check(num, n, fi, fl, first, si, sl, second):
n1 = num[fi : fl + 1 : 1]
n2 = num[si : sl + 1 : 1]
if n1 and n2 and len(n1) == first and len(n2) == second:
sum = int(int(n1) + int(n2))
third = len(str(sum))
ri = sl + 1
rl = ri + third - 1
res = num[ri : rl + 1 : 1]... | FUNC_DEF ASSIGN VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR... |
Given a string, the task is to find whether it contains an additive sequence or not. A string contains an additive sequence if its digits can make a sequence of numbers in which every number is addition of previous two numbers. You are required to complete the function which returns true if the string is a valid sequen... | def solve(i, nums, s, lst=[]):
if i >= len(nums) and s <= 2:
return False
if i >= len(nums):
return True
ans = False
for j in range(i, len(nums)):
if s < 2:
lst.append(nums[i : j + 1])
ans = ans or solve(j + 1, nums, s + 1, lst)
lst.pop()
... | FUNC_DEF LIST IF VAR FUNC_CALL VAR VAR VAR NUMBER RETURN NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR IF F... |
Given a string, the task is to find whether it contains an additive sequence or not. A string contains an additive sequence if its digits can make a sequence of numbers in which every number is addition of previous two numbers. You are required to complete the function which returns true if the string is a valid sequen... | n = 0
def dfs(s, a, l):
ans = 0
if a == n:
return 1 if len(l) >= 3 else 0
for i in range(a, n):
ans = ans * 10 + int(s[i])
if ans == 0:
if len(l) < 2:
l.append(ans)
b = dfs(s, a + 1, l)
l.pop()
return b
... | ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER IF VAR VAR RETURN FUNC_CALL VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR IF VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL... |
Given a string, the task is to find whether it contains an additive sequence or not. A string contains an additive sequence if its digits can make a sequence of numbers in which every number is addition of previous two numbers. You are required to complete the function which returns true if the string is a valid sequen... | def isAdditiveSequence(num):
def rec(first, second, rest):
if len(rest) == 0:
return True
total = str(first + second)
l = len(total)
if total == rest[:l]:
return rec(second, int(total), rest[l:])
for i in range(1, len(num) - 1):
for j in range(i ... | FUNC_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN... |
Given a string, the task is to find whether it contains an additive sequence or not. A string contains an additive sequence if its digits can make a sequence of numbers in which every number is addition of previous two numbers. You are required to complete the function which returns true if the string is a valid sequen... | def checkIsAdditive(nums):
if len(nums) < 3:
return True
for i in range(2, len(nums)):
if int(nums[i - 2]) + int(nums[i - 1]) != int(nums[i]):
return False
return True
def isAdditiveSequence(num):
additiveSubsequenceFound = False
def recur(str, sub):
nonlocal a... | FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER FUNC_DEF IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL... |
Given a string, the task is to find whether it contains an additive sequence or not. A string contains an additive sequence if its digits can make a sequence of numbers in which every number is addition of previous two numbers. You are required to complete the function which returns true if the string is a valid sequen... | n = 0
def find(s, a, b, c, d):
ans = 0
if a == n:
return 1 if d >= 3 else 0
for i in range(a, n):
ans = ans * 10 + int(s[i])
if ans == 0:
if b == -1 or c == -1:
if b == -1:
return find(s, a + 1, ans, c, d + 1)
else:
... | ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER IF VAR VAR RETURN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR IF VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR V... |
Given a string, the task is to find whether it contains an additive sequence or not. A string contains an additive sequence if its digits can make a sequence of numbers in which every number is addition of previous two numbers. You are required to complete the function which returns true if the string is a valid sequen... | def isAdditiveSequence(num):
S = num
A1 = ""
A2 = ""
A3 = ""
Re = ""
F = False
for i in range(1, len(S)):
for j in range(i + 1, len(S)):
A1 = S[:i]
A2 = S[i:j]
A3 = int(A1) + int(A2)
Re = str(int(A1)) + str(int(A2)) + str(int(A3))
... | FUNC_DEF ASSIGN VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIG... |
Given a string, the task is to find whether it contains an additive sequence or not. A string contains an additive sequence if its digits can make a sequence of numbers in which every number is addition of previous two numbers. You are required to complete the function which returns true if the string is a valid sequen... | def isAdditiveSequence(num):
def f(a, l1, l2):
if a == "":
return 0
if int(a) == l1 + l2:
return 1
for i in range(len(a)):
if (
len(a[:i]) > 0
and (int(a[:i]) == l1 + l2 or l2 == 0)
and f(a[i:], int(a[:i]), ... | FUNC_DEF FUNC_DEF IF VAR STRING RETURN NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER RETURN FUNC_CALL VAR ... |
Given a string, the task is to find whether it contains an additive sequence or not. A string contains an additive sequence if its digits can make a sequence of numbers in which every number is addition of previous two numbers. You are required to complete the function which returns true if the string is a valid sequen... | def rec(s, beg, l1, l2):
s1 = s[beg : beg + l1]
s2 = s[beg + l1 : beg + l1 + l2]
s3 = str(int(s1) + int(s2))
l3 = len(s3)
if beg + l1 + l2 + l3 > len(s):
return False
elif s3 == s[beg + l1 + l2 : beg + l1 + l2 + l3]:
if beg + l1 + l2 + l3 == len(s):
return True
... | FUNC_DEF ASSIGN VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP B... |
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.
Given an integer n, return all distinct solutions to the n-queens puzzle.
Each solution contains a distinct board configuration of the n-queens' placement, where 'Q' and '.' both indicate a queen a... | class Solution:
def solveNQueens(self, n):
result = []
visits = [0, 0, 0]
board = [["." for j in range(n)] for i in range(n)]
self.find(visits, n, 0, board, result)
return result + [
[row[::-1] for row in board]
for board in result
if n & ... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR STRING VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR RETURN BIN_OP VAR VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER BIN_OP VAR NUMBER STRING FUNC_DEF IF V... |
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.
Given an integer n, return all distinct solutions to the n-queens puzzle.
Each solution contains a distinct board configuration of the n-queens' placement, where 'Q' and '.' both indicate a queen a... | class Solution:
def solveNQueens(self, n):
def dfs(queens, xy_dif, xy_sum):
p = len(queens)
if p == n:
res.append(queens)
return
for i in range(n):
if i not in queens and p - i not in xy_dif and p + i not in xy_sum:
... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR LIST VAR BIN_OP VAR LIST BIN_OP VAR VAR BIN_OP VAR LIST BIN_OP VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR LIST LIST L... |
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.
Given an integer n, return all distinct solutions to the n-queens puzzle.
Each solution contains a distinct board configuration of the n-queens' placement, where 'Q' and '.' both indicate a queen a... | class Solution:
def solveNQueens(self, n):
def dfs(n, a, b, c, ans, d):
if n == 0:
ans = ans.append([(i * "." + "Q" + (len(a) - i - 1) * ".") for i in d])
return None
for i in range(len(a)):
if a[i] or b[n - 1 + i] or c[len(a) - 1 - i... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR STRING STRING BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER STRING VAR VAR RETURN NONE FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUM... |
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.
Given an integer n, return all distinct solutions to the n-queens puzzle.
Each solution contains a distinct board configuration of the n-queens' placement, where 'Q' and '.' both indicate a queen a... | class Solution:
def __init__(self):
self.result = []
self.visited = None
def solveNQueens(self, n):
self.visited = [(0) for i in range(n)]
self.__solve_n_queues(n, 0, [])
return self.result
@staticmethod
def __not_diagonal(x, y, curr_answer):
for c_x, c... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NONE FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER LIST RETURN VAR FUNC_DEF FOR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR RETURN NUMBER RETURN NUMBER VAR FUNC_DEF ASSIGN VAR LIST FOR VAR VAR EXPR ... |
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.
Given an integer n, return all distinct solutions to the n-queens puzzle.
Each solution contains a distinct board configuration of the n-queens' placement, where 'Q' and '.' both indicate a queen a... | class Solution:
def solveNQueens(self, n):
queens = []
res = []
def backtracking(n, k, queens):
if k > n:
return
elif len(queens) == n and k < n:
return
elif len(queens) == n and k == n:
temp = queens[:]
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF IF VAR VAR RETURN IF FUNC_CALL VAR VAR VAR VAR VAR RETURN IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP B... |
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.
Given an integer n, return all distinct solutions to the n-queens puzzle.
Each solution contains a distinct board configuration of the n-queens' placement, where 'Q' and '.' both indicate a queen a... | class Solution:
def __init__(self):
self.board = []
self.col_status = []
self.row_status = []
self.dia_status_1 = []
self.dia_status_2 = []
self.result = []
def placeQueen(self, row, n):
if row == n:
tmp = ["".join(el) for el in self.board]
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF IF VAR VAR ASSIGN VAR FUNC_CALL STRING VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR STRING ASSIGN VAR VAR... |
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.
Given an integer n, return all distinct solutions to the n-queens puzzle.
Each solution contains a distinct board configuration of the n-queens' placement, where 'Q' and '.' both indicate a queen a... | class Solution:
def helper(self, n, currentIndex, aux, rowsWithQueen, alll):
for i in range(n):
if i not in rowsWithQueen:
x, y = currentIndex - 1, i - 1
while aux[x][y] != "Q" and x >= 0 and y >= 0:
x -= 1
y -= 1
... | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER IF... |
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.
Given an integer n, return all distinct solutions to the n-queens puzzle.
Each solution contains a distinct board configuration of the n-queens' placement, where 'Q' and '.' both indicate a queen a... | class Solution:
def solveNQueens(self, n):
row = [x for x in range(n)]
table = []
for i in range(n):
table.append(row.copy())
result = self.solve(table, 0)
result_str = []
for x in result:
table_str = []
for y in x:
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING VAR STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUM... |
Chef Jessie has a lot of recipes with her (N). She often remembered the starting few characters of the recipe and forgot the rest. As all the great chefs do, Jessie also numbered the recipes depending on the priority. So, given the list of recipes along with their priorities answer Jessie’s queries.
Jessie’s queries ar... | N = int(input())
dic = {}
for i in range(N):
s, v = input().split()
v = int(v)
dic[s] = v
for i in range(int(input())):
S = input()
m = -20000000009
q = ""
for i, j in dic.items():
if i[: len(S)] == S:
if j > m:
q = i
m = j
if len(q) ==... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR VAR FUNC_CALL VAR IF VAR FUNC_CAL... |
Chef Jessie has a lot of recipes with her (N). She often remembered the starting few characters of the recipe and forgot the rest. As all the great chefs do, Jessie also numbered the recipes depending on the priority. So, given the list of recipes along with their priorities answer Jessie’s queries.
Jessie’s queries ar... | n = int(input())
a = []
b = []
for _ in range(n):
s = input().split()
a.append(s[0])
b.append(int(s[1]))
q = int(input())
for i in range(q):
x = input()
m = -(10**10)
for k in range(n):
y = a[k]
if x in y and x == y[0 : len(x)]:
m = max(m, b[k])
if m == -(10**10):... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER... |
Chef Jessie has a lot of recipes with her (N). She often remembered the starting few characters of the recipe and forgot the rest. As all the great chefs do, Jessie also numbered the recipes depending on the priority. So, given the list of recipes along with their priorities answer Jessie’s queries.
Jessie’s queries ar... | nr = int(input())
d = {}
for r in range(nr):
s, v = map(str, input().split())
d[int(v)] = s
q = int(input())
lis = []
for i in range(q):
lis.append(input())
l = list(d.keys())
l.sort(reverse=True)
ans = "NO"
for j in lis:
ans = "NO"
for k in l:
if len(j) <= len(d[k]):
a = d[k]
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL ... |
Chef Jessie has a lot of recipes with her (N). She often remembered the starting few characters of the recipe and forgot the rest. As all the great chefs do, Jessie also numbered the recipes depending on the priority. So, given the list of recipes along with their priorities answer Jessie’s queries.
Jessie’s queries ar... | n = int(input())
l = []
while n > 0:
n -= 1
k, v = input().split(" ")
v = int(v)
l.append([k, v])
q = int(input())
while q > 0:
q -= 1
s = input()
max = -1000000001
ans = ""
for k, v in l:
if k.startswith(s) and v > max:
max = v
ans = k
if ans == "... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FO... |
Chef Jessie has a lot of recipes with her (N). She often remembered the starting few characters of the recipe and forgot the rest. As all the great chefs do, Jessie also numbered the recipes depending on the priority. So, given the list of recipes along with their priorities answer Jessie’s queries.
Jessie’s queries ar... | di = {}
li = []
lis = []
for i in range(int(input())):
s, n = map(str, input().split())
di[n] = s
li.append(int(n))
li.sort(reverse=True)
for i in li:
lis.append(di[str(i)])
for i in range(int(input())):
q = input()
for j in range(len(lis)):
if q in lis[j] and q == lis[j][0 : len(q)]:
... | ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CAL... |
Chef Jessie has a lot of recipes with her (N). She often remembered the starting few characters of the recipe and forgot the rest. As all the great chefs do, Jessie also numbered the recipes depending on the priority. So, given the list of recipes along with their priorities answer Jessie’s queries.
Jessie’s queries ar... | cookbook = dict()
for i in range(int(input())):
foo = input().split()
priority = int(foo[1])
cookbook[priority] = foo[0]
it = [cookbook[i] for i in sorted(cookbook, reverse=True)]
for i in range(int(input())):
prefix = input().rstrip()
for j in it:
if j.startswith(prefix):
print(... | ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR IF ... |
Chef Jessie has a lot of recipes with her (N). She often remembered the starting few characters of the recipe and forgot the rest. As all the great chefs do, Jessie also numbered the recipes depending on the priority. So, given the list of recipes along with their priorities answer Jessie’s queries.
Jessie’s queries ar... | r = []
for _ in range(int(input())):
s, i = input().split()
r.append((s, int(i)))
r = sorted(r, key=lambda x: x[1], reverse=True)
for _ in range(int(input())):
inp = input()
done = 0
for s, i in r:
if s[: len(inp)] == inp:
print(s)
done = 1
break
if no... | ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR FUNC_CALL V... |
Chef Jessie has a lot of recipes with her (N). She often remembered the starting few characters of the recipe and forgot the rest. As all the great chefs do, Jessie also numbered the recipes depending on the priority. So, given the list of recipes along with their priorities answer Jessie’s queries.
Jessie’s queries ar... | class Recipe:
def __init__(self, text, priority):
self.text = text
self.priority = priority
N = int(input())
recipes = []
for n in range(N):
line = input().split()
recipes.append(Recipe(line[0], int(line[1])))
recipes.sort(key=lambda a: a.priority, reverse=True)
Q = int(input())
output = ... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST F... |
Chef Jessie has a lot of recipes with her (N). She often remembered the starting few characters of the recipe and forgot the rest. As all the great chefs do, Jessie also numbered the recipes depending on the priority. So, given the list of recipes along with their priorities answer Jessie’s queries.
Jessie’s queries ar... | def keyFn(tp):
return tp[1]
n = int(input())
recipes = []
i = 0
while i < n:
line = input().split()
recipes.append((line[0], int(line[1])))
i += 1
q = int(input())
i = 0
srec = sorted(recipes, key=keyFn, reverse=True)
while i < q:
name = input()
ans = "NO"
for items in srec:
if ite... | FUNC_DEF RETURN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER WHILE VA... |
Chef Jessie has a lot of recipes with her (N). She often remembered the starting few characters of the recipe and forgot the rest. As all the great chefs do, Jessie also numbered the recipes depending on the priority. So, given the list of recipes along with their priorities answer Jessie’s queries.
Jessie’s queries ar... | class TrieNode:
def __init__(self):
self.children = [None] * 27
self.ispresent = 0
self.priority = "aa"
self.index = -1
class Trie:
def __init__(self):
self.root = self.getnode()
def getnode(self):
return TrieNode()
def getind(self, ch):
if c... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NONE NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF IF VAR STRING RETURN NUMBER RETURN BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR F... |
Chef Jessie has a lot of recipes with her (N). She often remembered the starting few characters of the recipe and forgot the rest. As all the great chefs do, Jessie also numbered the recipes depending on the priority. So, given the list of recipes along with their priorities answer Jessie’s queries.
Jessie’s queries ar... | n = int(input())
slist = []
plist = []
while n > 0:
n = n - 1
s, p = input().split()
slist.append(s)
plist.append(p)
r = int(input())
while r > 0:
r = r - 1
c = -10000000000
flag = 0
s1 = input()
for i in range(len(slist)):
dummy = slist[i]
v = dummy.find(s1)
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMB... |
Chef Jessie has a lot of recipes with her (N). She often remembered the starting few characters of the recipe and forgot the rest. As all the great chefs do, Jessie also numbered the recipes depending on the priority. So, given the list of recipes along with their priorities answer Jessie’s queries.
Jessie’s queries ar... | n = int(input())
recipes = {}
for i in range(n):
recipe, priority = input().split()
priority = int(priority)
recipes[recipe] = priority
q = int(input())
for i in range(q):
query = input().strip()
max_priority = -(10**9) - 1
max_recipe = "NO"
for recipe in recipes:
if recipe.startswit... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN... |
Chef Jessie has a lot of recipes with her (N). She often remembered the starting few characters of the recipe and forgot the rest. As all the great chefs do, Jessie also numbered the recipes depending on the priority. So, given the list of recipes along with their priorities answer Jessie’s queries.
Jessie’s queries ar... | n = int(input())
d = dict()
for _ in range(n):
aa = input().split()
s = aa[0]
v = int(aa[1])
d[s] = v
q = int(input())
for _ in range(q):
qi = input()
value = None
recep = None
for i in d:
if i.startswith(qi):
if value is None or value < d[i]:
value = ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NONE ASSIGN VAR N... |
Chef Jessie has a lot of recipes with her (N). She often remembered the starting few characters of the recipe and forgot the rest. As all the great chefs do, Jessie also numbered the recipes depending on the priority. So, given the list of recipes along with their priorities answer Jessie’s queries.
Jessie’s queries ar... | N = int(input())
temp_list = []
for i in range(N):
r, p = input().split()
temp_list.append((r, int(p)))
rec_list = sorted(temp_list, key=lambda lis: lis[1], reverse=True)
Q = int(input())
for i in range(Q):
current_rec = "NO"
current_rec_pri = -(10**9)
sfc = input()
sfc_len = len(sfc)
for j ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP NUMBER NUMB... |
Chef Jessie has a lot of recipes with her (N). She often remembered the starting few characters of the recipe and forgot the rest. As all the great chefs do, Jessie also numbered the recipes depending on the priority. So, given the list of recipes along with their priorities answer Jessie’s queries.
Jessie’s queries ar... | a = int(input())
b = []
for _ in range(a):
aa = input().split()
b.append((aa[0], int(aa[1])))
b = sorted(b, key=lambda x: x[1], reverse=True)
ab = int(input())
for i in range(ab):
cc = input()
for i in b:
if len(cc) <= len(i[0]) and i[0][: len(cc)] == cc:
print(i[0])
brea... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ... |
Chef Jessie has a lot of recipes with her (N). She often remembered the starting few characters of the recipe and forgot the rest. As all the great chefs do, Jessie also numbered the recipes depending on the priority. So, given the list of recipes along with their priorities answer Jessie’s queries.
Jessie’s queries ar... | n = int(input())
li = []
for i in range(n):
string, pri = input().split()
pri = int(pri)
li.append([string, pri])
li.sort(key=lambda x: x[1], reverse=True)
q = int(input())
for i in range(q):
start = input()
f = 0
for i in range(n):
if li[i][0].startswith(start):
f = 1
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR N... |
Chef Jessie has a lot of recipes with her (N). She often remembered the starting few characters of the recipe and forgot the rest. As all the great chefs do, Jessie also numbered the recipes depending on the priority. So, given the list of recipes along with their priorities answer Jessie’s queries.
Jessie’s queries ar... | import sys
t = int(input())
list1 = []
for _ in range(t):
s = input()
n = len(s)
num = ""
for i in range(len(s)):
if s[n - i - 1] == " ":
list1.append([s[0 : n - i - 1], int(num)])
break
else:
num = s[n - i - 1] + num
n = int(input())
for _ in range(n... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER STRING EXPR FUNC_CALL VAR LIST VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR... |
Chef Jessie has a lot of recipes with her (N). She often remembered the starting few characters of the recipe and forgot the rest. As all the great chefs do, Jessie also numbered the recipes depending on the priority. So, given the list of recipes along with their priorities answer Jessie’s queries.
Jessie’s queries ar... | n = int(input())
s = []
a = []
for i in range(n):
si, vi = input().split()
vi = int(vi)
a.append(vi)
s.append(si)
q = int(input())
for j in range(0, q):
qi = input()
ma = -20000000009
pos = -1
for k in range(0, n):
if s[k].startswith(qi):
if a[k] > ma:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR N... |
Chef Jessie has a lot of recipes with her (N). She often remembered the starting few characters of the recipe and forgot the rest. As all the great chefs do, Jessie also numbered the recipes depending on the priority. So, given the list of recipes along with their priorities answer Jessie’s queries.
Jessie’s queries ar... | def twstr():
recipes = dict()
for n in range(int(input())):
recipe, priority = input().strip().split()
priority = int(priority)
recipes[priority] = recipe
for q in range(int(input())):
start = input().strip()
recipe = "NO"
for prio in sorted(recipes.keys(), re... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR ... |
Chef Jessie has a lot of recipes with her (N). She often remembered the starting few characters of the recipe and forgot the rest. As all the great chefs do, Jessie also numbered the recipes depending on the priority. So, given the list of recipes along with their priorities answer Jessie’s queries.
Jessie’s queries ar... | n = int(input())
recipe = []
for _ in range(n):
si, vi = map(str, input().split())
recipe.append([si, int(vi)])
recipe.sort(key=lambda x: x[1], reverse=True)
for i in range(int(input())):
q = input()
for j in range(len(recipe)):
if q == recipe[j][0][: len(q)]:
print(recipe[j][0])
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FU... |
Chef Jessie has a lot of recipes with her (N). She often remembered the starting few characters of the recipe and forgot the rest. As all the great chefs do, Jessie also numbered the recipes depending on the priority. So, given the list of recipes along with their priorities answer Jessie’s queries.
Jessie’s queries ar... | res = []
for _ in range(int(input())):
a, b = map(str, input().split())
res.append([a, int(b)])
res.sort(key=lambda x: x[-1])
for _ in range(int(input())):
check = input().strip()
f = 1
for i in range(len(res) - 1, -1, -1):
if res[i][0][: len(check)] == check:
f = 0
a... | ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL ... |
Chef Jessie has a lot of recipes with her (N). She often remembered the starting few characters of the recipe and forgot the rest. As all the great chefs do, Jessie also numbered the recipes depending on the priority. So, given the list of recipes along with their priorities answer Jessie’s queries.
Jessie’s queries ar... | numrec = int(input())
reclst = {}
recval = []
for i in range(numrec):
p, s = input().split(" ")
reclst.update({s: p})
querynum = int(input())
for j in range(querynum):
query = input()
recval = [int(key) for key, value in reclst.items() if value.startswith(query)]
recval.sort(reverse=True)
try:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR DICT VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC... |
Chef Jessie has a lot of recipes with her (N). She often remembered the starting few characters of the recipe and forgot the rest. As all the great chefs do, Jessie also numbered the recipes depending on the priority. So, given the list of recipes along with their priorities answer Jessie’s queries.
Jessie’s queries ar... | S = []
for _ in range(int(input())):
s, v = input().split()
v = int(v)
S.append([v, s])
S.sort(reverse=True)
for _ in range(int(input())):
s = input()
found = False
for i in range(len(S)):
if S[i][1].find(s) == 0:
print(S[i][1])
found = True
break
... | ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def isSafeCell(self, M, n, r, c):
return r >= 0 and r < n and c >= 0 and c < n and M[r][c] > 0
def findPathUtil(self, matrix, n, res, r, c):
if r == n - 1 and c == n - 1:
res[r][c] = 1
return True
if self.isSafeCell(matrix, n, r, c):
... | CLASS_DEF FUNC_DEF RETURN VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VA... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def recur(self, i, j, n, matrix, ans):
if i > n - 1 or j > n - 1:
return False
ans[i][j] = 1
if i == n - 1 and j == n - 1:
return True
for e in range(1, matrix[i][j] + 1):
if self.recur(i, j + e, n, matrix, ans):
re... | CLASS_DEF FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR RETURN NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR ... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def find_rat_path(self, i, j, matrix, n, found):
if found[0]:
return
if i == n - 1 and j == n - 1:
found[0] = True
for r in range(n):
for c in range(n):
if matrix[r][c] != -1:
matrix[r][c... | CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN IF VAR VAR VAR NUMBER RETURN ASSIGN VAR VAR VAR V... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def isSafe(self, i, j, matrix):
n = len(matrix)
return i >= 0 and j >= 0 and i < n and j < n and matrix[i][j] != 0
def solve(self, matrix, x, y, sol, n):
if x == n - 1 and y == n - 1:
sol[x][y] = 1
return True
if self.isSafe(x, y, matrix)... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR NUMBER IF... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def __init__(self):
self.matrix = None
self.final_hops = None
self.cur_hops = None
self.min_hops = None
def ShortestDistance(self, matrix):
self.matrix = matrix
self.final_hops = []
self.cur_hops = []
self.min_hops = float("inf")
... | CLASS_DEF FUNC_DEF ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR NONE FUNC_DEF ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER RETURN LIST LIST NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR FUNC_CALL VAR STRING RETURN LIST LIST NUMBER ASSIG... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def find(self, matrix, i, j, n, m, path):
if i >= n or j >= m or i < 0 or j < 0:
return False
elif i == n - 1 and j == m - 1:
path[i][i] = "1"
self.res.append([[*row] for row in path])
path[i][j] = "0"
return True
e... | CLASS_DEF FUNC_DEF IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR STRING EXPR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR VAR VAR STRING RETURN NUMBER IF VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR STRING FOR VAR FUNC... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | def isSafe(maze, x, y):
if x >= 0 and x < len(maze) and y >= 0 and y < len(maze) and maze[x][y] != 0:
return True
return False
def solveMaze(maze):
sol = [[(0) for i in range(len(maze))] for j in range(len(maze))]
if solveMazeUtil(maze, 0, 0, sol) == False:
return [[-1]]
return sol... | FUNC_DEF IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER RETURN LIST LIST NUMBER RETURN VAR FUNC_DEF IF VAR... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
NO_PATH = [[-1]]
def __init__(self):
self.ans = None
def ShortestDistance(self, matrix):
m, n = len(matrix), len(matrix[0])
if m == 1 and n == 1:
return [[1]]
if matrix[0][0] == 0:
return self.NO_PATH
m, n = len(matrix), len(m... | CLASS_DEF ASSIGN VAR LIST LIST NUMBER FUNC_DEF ASSIGN VAR NONE FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN LIST LIST NUMBER IF VAR NUMBER NUMBER NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NONE EXPR FUNC_CALL VAR NUMBER NU... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def ShortestDistance(self, matrix):
m, n = len(matrix), len(matrix[0])
ans = []
for i in range(m):
ans.append([])
for j in range(n):
ans[i].append(0)
def valid(matrix, i, j):
if i < len(matrix) and j < len(matrix[0... | 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 EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | import sys
class Solution:
def min_jumps(self, dp, n, matrix, i, j):
if i < 0 or i >= n or j < 0 or j >= n:
return 0
if i == n - 1 and j == n - 1:
dp[i][j] = 1
return 1
if matrix[i][j] == 0:
return 0
k = 1
while dp[i][j] == 0... | IMPORT CLASS_DEF FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR RETURN NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP V... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def ShortestDistance(self, matrix):
n = len(matrix)
ans = [([0] * n) for i in range(n)]
def fun(i, j):
if i == n - 1 and j == n - 1:
ans[i][j] = 1
return 1
if i >= n or j >= n or matrix[i][j] == 0:
retu... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBE... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | def isSafe(x, y, n, mat):
if x < 0 or y < 0 or x > n - 1 or y > n - 1 or mat[x][y] == 0:
return False
return True
class Solution:
def ShortestDistance(self, mat):
self.res = [[(0) for i in range(len(mat))] for i in range(len(mat))]
n = len(mat)
if mat[0][0] == 0 and n != 1... | FUNC_DEF IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER NUMBER VAR NUMBER RETURN LIST LIST N... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def ShortestDistance(self, a):
i = 0
j = 0
def px(m):
for i in range(len(m)):
for j in range(len(m[0])):
print(m[i][j], end=" ")
print()
print()
sol = []
for _ in range(len(a)):
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def ShortestDistance(self, matrix):
r = len(matrix)
c = len(matrix[0])
self.ans = [[(0) for i in range(r)] for j in range(c)]
self.ans[r - 1][c - 1] = 1
if r == 1 and c == 1:
return [[1]]
if matrix[0][0] == 0:
return [[-1]]
... | 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 BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER RETURN LIST LIST NUMBER IF VAR NUMBER NUMBER NUMBER RETURN LIST LIST NUMBER FUNC_DEF IF VAR VAR... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def __init__(self):
self.flag = False
def ShortestDistance(self, matrix):
n = len(matrix)
if n == 1:
return [[1]]
if matrix[0][0] == 0:
return [[-1]]
res = [[(0) for i in range(n)] for j in range(n)]
def rec(i, j):
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN LIST LIST NUMBER IF VAR NUMBER NUMBER NUMBER RETURN LIST LIST NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER RETURN IF VAR NUMBER VAR NUMBER V... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def ShortestDistance(self, l):
n = len(l)
def ss(i, j, t):
if i == n - 1 and j == n - 1:
t[i][j] = 1
return True
if i < 0 or j < 0 or i >= n or j >= n or l[i][j] == 0:
return False
t[i][j] = 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR ... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def ShortestDistance(self, matrix):
def DeapthFirst(position):
x, y = position
if 0 <= x < len(matrix) and 0 <= y < len(matrix):
if x == len(matrix) - 1 and y == len(matrix[0]) - 1:
matrix[x][y] = "1"
return 1
... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR VAR IF NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR STRING RETURN NUMBER IF VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR NU... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def helper(self, x, y):
if not self.valid(x, y):
return
self.ans[x][y] = 1
if (x, y) == (self.row - 1, self.col - 1):
return True
for i in range(1, matrix[x][y] + 1):
if self.helper(x, y + i) or self.helper(x + i, y):
... | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN ASSIGN VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR NUMBER RETURN NUMBER FUNC... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def helper(self, matrix, v, i, j):
n = len(matrix)
if i == n - 1 and j == n - 1:
v[i][j] = 1
return True
if i < 0 or j < 0 or i >= n or j >= n or matrix[i][j] == 0:
return False
v[i][j] = 1
for k in range(1, matrix[i][j] + ... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR B... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def inbound(self, i, j, n, matrix):
if i < n and j < n and matrix[i][j] != 0:
return True
return False
def ratmaze(self, i, j, matrix, res, n):
if i == n - 1 and j == n - 1:
res[i][j] = 1
return True
if self.inbound(i, j, n, m... | CLASS_DEF FUNC_DEF IF VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR BIN_... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def ShortestDistance(self, matrix):
self.M = len(matrix)
self.N = len(matrix[0])
result = [[(0) for _ in range(self.N)] for _ in range(self.M)]
if self.solveMaze(matrix, 0, 0, result):
return result
else:
return [[-1]]
def solveMa... | 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 IF FUNC_CALL VAR VAR NUMBER NUMBER VAR RETURN VAR RETURN LIST LIST NUMBER FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN NUMBER IF F... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def ShortestDistance(self, matrix):
n = len(matrix)
cond = True
ans = []
arr = [[(0) for _ in range(n)] for _ in range(n)]
def fun(i, j):
nonlocal cond, ans, arr
if i == n - 1 and j == n - 1:
arr[i][j] = 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER RETURN IF VAR NUMBER RETURN FOR VAR FUNC_CALL... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def ShortestDistance(self, matrix):
n = len(matrix[0])
ret = [[-1]]
mat = [[(0) for j in range(n)] for i in range(n)]
if self.Solve_maze(matrix, 0, 0, n, mat) == True:
return mat
return ret
def is_block_valid(self, matrix, x, y, n):
i... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST LIST NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR NUMBER RETURN VAR RETURN VAR FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_D... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def distance(self, matrix, res, n, i, j):
if i >= n or j >= n:
return False
res[i][j] = 1
if i == n - 1 and j == n - 1:
return True
jump = matrix[i][j]
for k in range(1, jump + 1):
if self.distance(matrix, res, n, i, j + k)... | CLASS_DEF FUNC_DEF IF VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR R... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def ShortestDistance(self, matrix):
n, m = len(matrix), len(matrix[0])
ans = [([0] * m) for _ in range(n)]
def solve(i, j):
if i == n - 1 and j == m - 1:
ans[i][j] = 1
return True
if i >= n or i < 0 or j >= m or j < 0 ... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VA... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def ShortestDistance(self, matrix):
n = len(matrix)
ans = [([0] * n) for i in range(n)]
exists = 0
def dfs(i, j):
nonlocal exists
if i == n - 1 and j == n - 1:
ans[i][j] = 1
exists = 1
return Tr... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER RETURN NUMBER IF NUMBER VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VA... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def ShortestDistance(self, mat):
def issafe(i, j, n, mat):
if i >= 0 and i < n and j >= 0 and j < n:
return True
return False
def util(n, mat, i, j, res):
if i == n - 1 and j == n - 1:
res[i][j] = 1
... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR N... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def ShortestDistance(self, matrix):
n = len(matrix)
a = [[(0) for i in range(n)] for i in range(n)]
if self.tFW(0, 0, n, matrix, a):
return a
return [[-1]]
def tFW(self, i, j, n, matrix, a):
if i > n - 1 or j > n - 1:
return False... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR RETURN VAR RETURN LIST LIST NUMBER FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP ... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def ShortestDistance(self, matrix):
def findshorted(matrix, visited, i, j, n, path=0):
if i == n - 1 and j == n - 1:
visited[i][j] = 1
return visited
if 0 <= i < n and 0 <= j < n:
if matrix[i][j] != 0 and visited[i][j]... | CLASS_DEF FUNC_DEF FUNC_DEF NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN VAR IF NUMBER VAR VAR NUMBER VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VA... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def ShortestDistance(self, matrix):
m, n = len(matrix), len(matrix[0])
valid = (
lambda x, y: (x, y) == (n - 1, m - 1)
or 0 <= x < n
and 0 <= y < m
and matrix[y][x] != 0
)
ans = [([0] * m) for _ in range(n)]
de... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VA... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def ShortestDistance(self, matrix):
output = []
totalRows = len(matrix)
totalCols = len(matrix[0])
arr = []
def recurRat(row, col, arr):
if row == totalRows - 1 and col == totalCols - 1:
arr.append([row, col])
retu... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR RETURN NUMBER IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR ASSIG... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def isSafe(self, matrix, i, j):
if i >= len(matrix) or j >= len(matrix) or matrix[i][j] == 0:
return False
return True
def solve(self, matrix, i, j, arr):
if i == len(matrix) - 1 and j == len(matrix) - 1:
arr[i][j] = 1
return True
... | CLASS_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def ShortestDistance(self, matrix):
def f(i, j):
if i == n - 1 and j == n - 1:
ans[i][j] = 1
return True
if i > n - 1 or j > n - 1:
return False
if matrix[i][j] == 0:
return False
... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def ShortestDistance(self, matrix):
n = len(matrix)
result = [[(0) for i in range(n)] for j in range(n)]
result[0][0] = 1
return result if self.walk(matrix, 0, 0, result) else [[-1]]
def walk(self, matrix, x, y, result):
n = len(matrix)
if x == n... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER NUMBER RETURN FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR LIST LIST NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER RET... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def ShortestDistance(self, m):
def rec(m, i, j, ans):
if i == n - 1 and j == n - 1:
ans[i][j] = 1
return True
if i < 0 or j < 0 or i >= n or j >= n or m[i][j] == 0:
return False
for x in range(m[i][j]):
... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR RETURN NUMBER... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def ShortestDistance(self, matrix):
def dfs(i, j):
if i == len(matrix) - 1 and j == len(matrix) - 1:
l[i][j] = 1
return True
if (
i < 0
or j < 0
or i >= len(matrix)
or j ... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR N... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def ShortestDistance(self, matrix):
def solve(i, j, res):
nonlocal matrix
if i == len(res) - 1 and j == len(res[0]) - 1:
return True
if i < 0 or i >= len(res) or j < 0 or j >= len(res[0]) or matrix[i][j] == 0:
return False... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN NUMBER IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def ShortestDistance(self, matrix):
n = len(matrix)
self.res = [([0] * n) for i in range(n)]
def travel(i, j, matrix):
if (i, j) == (n - 1, n - 1):
self.res[i][j] = 1
return True
if i > n - 1 or i < 0 or j < 0 or j > n... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def ShortestDistance(self, matrix):
n = len(matrix)
visit = [[(0) for i in range(n)] for i in range(n)]
def recsol(row, col):
if row == n - 1 and col == n - 1:
visit[row][col] = 1
return True
if row < n and col < n and... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR NU... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def ShortestDistance(self, matrix):
n = len(matrix)
m = len(matrix[0])
paths = self.gridHop(0, 0, n, m, matrix, [])
if not paths:
return [[-1]]
output = [([0] * m) for _ in range(n)]
for i, j in paths[0]:
output[i][j] = 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR LIST IF VAR RETURN LIST LIST NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN VAR FUNC_DEF IF VAR BIN_OP VAR NUMBER... |
A Maze is given as n*n matrix of blocks where source block is the upper left most block i.e., matrix[0][0] and destination block is lower rightmost block i.e., matrix[n-1][n-1]. A rat starts from source and has to reach the destination. The rat can move in only two directions: first forward if possible or down. If mult... | class Solution:
def isSafe(self, i, j, matrix):
n = len(matrix)
if 0 <= i < n and 0 <= j < n and matrix[i][j] != 0:
return True
return False
def ShortestDistance(self, matrix):
n = len(matrix)
paths = [([0] * n) for i in range(n)]
def recurse(i, j):... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF NUMBER VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN NUMBER IF... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.