description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
def helper(i, j, a):
if i in [-1, len(grid)] or j in [-1, len(grid[0])] or grid[i][j] in [-1, 0]:
return a
y = grid[i][j]
x = a + y
grid[i][j] = -1
a = max(
... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF IF VAR LIST NUMBER FUNC_CALL VAR VAR VAR LIST NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR VAR LIST NUMBER NUMBER RETURN VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def __init__(self):
self.moves = [(1, 0), (-1, 0), (0, 1), (0, -1)]
def getMaximumGold(self, grid: List[List[int]]) -> int:
best = 0
for i in range(len(grid)):
for j in range(len(grid[i])):
if self.canMove(i, j, grid, set()):
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER ASSIG... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, a: List[List[int]]) -> int:
def dfs(a, r, c, curSum, res):
res[0] = max(res[0], curSum)
temp = a[r][c]
a[r][c] = -1
directions = [[0, 1], [0, -1], [1, 0], [-1, 0]]
for d in directions:
nr, ... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR FUN... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def _getMaximumGold(self, cur_sum, i, j, grid):
m = len(grid)
n = len(grid[0])
max_sum = cur_sum
if i + 1 < m and grid[i + 1][j] != 0:
val = grid[i + 1][j]
grid[i + 1][j] = 0
temp_max_sum = self._getMaximumGold(cur_sum + val, i + 1... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VA... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
self.ret = 0
self.grid = grid
for i in range(len(grid)):
for j in range(len(grid[0])):
if grid[i][j] != 0:
self.dfs(i, j, 0)
return self.ret
def dfs(self, i, ... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR IF NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | def is_valid_cell(row, col, rows, cols):
return 0 <= row < rows and 0 <= col < cols
class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
rows = len(grid)
cols = len(grid[0])
max_amount = 0
def backtrack(row, col, rows, cols, grid):
if not is_val... | FUNC_DEF RETURN NUMBER VAR VAR NUMBER VAR VAR CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VA... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
def dfs(i, j, seen):
if (
i < 0
or j < 0
or j >= len(grid[0])
or i >= len(grid)
or (i, j) in seen
or grid[i][j] == 0
... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF IF VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CAL... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
self.orig_grid = grid
self.M = len(grid)
self.N = len(grid[0])
max_gold = 0
for i in range(self.M):
for j in range(self.N):
self.soln = [[(0) for j in range(self.N)] for i in ... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
self.maxGold = 0
for i in range(len(grid)):
for j in range(len(grid[0])):
if grid[i][j] > 0:
used = set()
used.add((i, j))
self.dfs(i, j, 0... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR RETURN VAR VAR FUNC_DEF VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR FO... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
n = len(grid)
m = len(grid[0])
p = 0
for i in range(n):
for j in range(m):
if grid[i][j] != 0:
p = max(p, self.dfs(grid, i, j, m, n))
return p
def dfs... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR F... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
def dfs(i: int, j: int, sum_so_far: int, seen: set) -> int:
if i < 0 or i >= m or j < 0 or j >= n or not grid[i][j] or (i, j) in seen:
return sum_so_far
seen.add((i, j))
sum_so_far +... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FU... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getNeighbors(self, root, grid):
deltas = [(0, 1), (1, 0), (0, -1), (-1, 0)]
x, y = root
return [
(x + dx, y + dy)
for dx, dy in deltas
if 0 <= x + dx < len(grid) and 0 <= y + dy < len(grid[x])
]
def dfs(self, root, grid, v... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR RETURN BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FO... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
visited = set()
max_gold = 0
def dfs(r, c, max_gold):
if (r, c) in visited or grid[r][c] == 0:
return max_gold
visited.add((r, c))
for i, j in ((1, 0), (0, 1), (-1, 0... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER IF NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN ... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
if not grid:
return 0
def dfs(i, j, gold, visited):
nonlocal ans
if (
i < 0
or i >= rows
or j < 0
or j >= cols
... | CLASS_DEF FUNC_DEF VAR VAR VAR IF VAR RETURN NUMBER FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VA... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
def nextPos(r, c):
if r > 0:
yield r - 1, c
if r < m - 1:
yield r + 1, c
if c > 0:
yield r, c - 1
if c < n - 1:
yield r, c... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF IF VAR NUMBER EXPR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER EXPR BIN_OP VAR NUMBER VAR IF VAR NUMBER EXPR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR ... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
max_total = 0
num_rows = len(grid)
num_cols = len(grid[0])
for i in range(num_rows):
for j in range(num_cols):
if grid[i][j] == 0:
continue
start_p... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST VAR VAR VAR VAR VAR WHILE VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR NUMBER ASSI... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
d = [[-1, 0], [0, 1], [1, 0], [0, -1]]
m = len(grid)
if m == 0:
return 0
n = len(grid[0])
visited = []
visited_in = []
for i in range(m):
for j in range(n):
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR N... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
if not grid:
return 0
m, n = len(grid), len(grid[0])
result = 0
best_path = set()
def dfs(i, j, visited, res):
nonlocal result, best_path
if res > result:
... | CLASS_DEF FUNC_DEF VAR VAR VAR IF VAR RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def __init__(self):
self.max = 0
def getMaximumGold(self, grid: List[List[int]]) -> int:
for i in range(len(grid)):
for j in range(len(grid[i])):
self.max = max(self.dfs(grid, i, j), self.max)
return self.max
def dfs(self, grid, i, j):
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FUNC_DEF VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR VAR FUNC_DEF IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER RETURN ... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def __init__(self):
self.next_moves = [(0, 1), (0, -1), (1, 0), (-1, 0)]
def getMaximumGold(self, grid: List[List[int]]) -> int:
def dfs(row, col):
if grid[row][col] == 0:
return 0
gold = grid[row][col]
grid[row][col] = 0
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF VAR VAR VAR FUNC_DEF IF VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF NUMBER VAR VAR NUMBER ... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
def dfs(row, col, cur_sum, visited):
if (
row < 0
or col < 0
or row >= len(grid)
or col >= len(grid[0])
or visited[row][col] == 1
... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF IF VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN ASSIGN VAR VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBE... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
m = len(grid)
n = len(grid[0])
def visit(i, j):
visited[i][j] = True
gold = 0
if i > 0 and not visited[i - 1][j]:
gold = max(gold, visit(i - 1, j))
if i <... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
res = 0
def dfs(x, y, grid):
if (
x < 0
or x > len(grid) - 1
or y < 0
or y > len(grid[0]) - 1
or grid[x][y] == 0
):
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
res = 0
for i in range(len(grid)):
for j in range(len(grid[0])):
res = max(res, self.find(grid, i, j))
return res
def find(self, grid, i, j):
if i < 0 or j < 0 or i >= len(grid) ... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR FUNC_DEF IF VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR RETURN NUMBER ASS... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
m, n = len(grid), len(grid[0])
csum = msum = 0
def backtrack(r, c):
direct = [(r - 1, c), (r + 1, c), (r, c + 1), (r, c - 1)]
nonlocal msum, csum
isbool = True
for p, q i... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_DEF ASSIGN VAR LIST BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR ASSIGN VAR... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
ans = 0
def bfs(a, s, d, f):
nonlocal ans
q = collections.deque([(a, s, d, f)])
while q:
j, k, tot, seen = q.popleft()
for m, n in [[0, 1], [0, -1], [1, 0], [... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR LIST VAR VAR VAR VAR WHILE VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FOR VAR VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER VAR FU... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
checked = set()
maximum = 0
for x in range(len(grid)):
for y in range(len(grid[0])):
if grid[x][y]:
visited = set()
value = self.recursive(0, x, y, gri... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR VAR FUNC_DEF IF VAR VAR VAR NUMBER... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | import sys
class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
rows = len(grid)
cols = len(grid[0])
def isValid(start, grid):
valid = []
r, c = start
up, right, left, down = True, True, True, True
if r == 0:
... | IMPORT CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR LIST ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER I... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
self.max_gold = 0
def backtrack(grid, row, col, current):
if 0 <= row < len(grid) and 0 <= col < len(grid[0]) and grid[row][col]:
temp = grid[row][col]
grid[row][col] = 0
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER FUNC_DEF IF NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP ... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
if not grid or not grid[0]:
return 0
maxGold = 0
m, n = len(grid), len(grid[0])
def dfs(i, j):
res = 0
if grid[i][j] == 0:
return 0
tmp = grid[i][... | CLASS_DEF FUNC_DEF VAR VAR VAR IF VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR VAR LIST LIST BIN_OP VAR NUMBER VAR LIST BIN_OP VAR NUMBER VA... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, A: List[List[int]]) -> int:
def dfs(i, j):
if not (0 <= i < m and 0 <= j < n):
return 0
if A[i][j] == 0:
return 0
if (i, j) in path:
return 0
path.add((i, j))
... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF IF NUMBER VAR VAR NUMBER VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VA... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def dfs(self, cur_gold, max_gold, grid, visited, i, j):
if (
i < 0
or i >= len(grid)
or j < 0
or j >= len(grid[0])
or visited[i][j] == 1
or grid[i][j] == 0
):
return
visited[i][j] = 1
... | CLASS_DEF FUNC_DEF IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR EX... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
self.res = 0
m, n = len(grid), len(grid[0])
def dfs(x, y, visited, cnt):
if any(
0 <= nx < m
and 0 <= ny < n
and grid[nx][ny] != 0
and (nx, ny... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF IF FUNC_CALL VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR VAR LIST LIST BIN_OP VAR NUMBER VAR LIST BIN_OP VAR NUMBER VAR LIST VAR BIN_OP VAR NUMBER LIST VAR BIN_OP VAR NUMBER FOR V... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def explore(self, grid, row, col):
if (
row < 0
or row >= len(grid)
or col < 0
or col >= len(grid[0])
or grid[row][col] == 0
):
return 0
total = curr_gold = grid[row][col]
max_gold = grid[row][co... | CLASS_DEF FUNC_DEF 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 VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_O... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
self.nums = grid.copy()
self.results = []
self.visited = [
[(False) for i in range(len(grid[0]))] for i in range(len(grid))
]
for i in range(len(grid)):
for j in range(len(grid[0]... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER RE... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
maxCount = 0
N = len(grid)
M = len(list(zip(*grid)))
for row in range(N):
for col in range(M):
if grid[row][col] != 0:
maxCount = max(self.backtrack(grid, row, col... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR A... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
def getGold(i, j, s, money):
nonlocal mx
for c1, c2 in [(i + 1, j), (i - 1, j), (i, j + 1), (i, j - 1)]:
if (
(c1, c2) not in s
and 0 <= c1 < len(grid)
... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF FOR VAR VAR LIST BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
grid_height, grid_width = len(grid), len(grid[0])
visited = set()
def helper(i, j, gold=0):
if (
i < 0
or i >= grid_height
or j < 0
or j >= gr... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_DEF NUMBER IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER N... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
ans = 0
row = len(grid)
if not row:
return 0
col = len(grid[0])
if not col:
return 0
dc = [0, 1, 0, -1]
dr = [-1, 0, 1, 0]
def dfs(i, j):
if i... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR RETURN NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER RETURN ... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
seen = set()
n, m = len(grid), len(grid[0])
self.ans = 0
def dfs(r, c, cur=0):
seen.add((r, c))
cur += grid[r][c]
for dx, dy in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FOR VAR VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF NUMBER V... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
self.ans = 0
m = len(grid)
n = len(grid[0])
def backtrack(i, j, sumup):
nonlocal n, m
if i < 0 or i > m - 1 or j < 0 or j > n - 1 or grid[i][j] == 0:
return
s... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
n = len(grid)
m = len(grid[0])
values = [[(0) for j in range(0, m)] for i in range(0, n)]
visited = [[(0) for j in range(0, m)] for i in range(0, n)]
_max = 0
for i in range(0, n):
fo... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaxGoldHelper(self, visited, grid, curx, cury):
if (curx, cury) in visited:
return 0
visited.add((curx, cury))
ret = grid[cury][curx]
max_recur = 0
for nextx, nexty in [
(curx - 1, cury),
(curx + 1, cury),
... | CLASS_DEF FUNC_DEF IF VAR VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR LIST BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER A... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
def is_valid(i, j):
if 0 <= i < m and 0 <= j < n:
return True
return False
def dfs(i, j, visited, cur_sum):
visited.add((i, j))
cur_sum += grid[i][j]
... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF IF NUMBER VAR VAR NUMBER VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL V... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
nr, nc = len(grid), len(grid[0])
delta = [(1, 0), (-1, 0), (0, 1), (0, -1)]
def dfs(i, j):
gold, grid[i][j] = grid[i][j], 0
max_gold = 0
for dx, dy in delta:
x, y = i... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF NUMBER VAR VAR NUMBER VAR ... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
def getMaxGold(y, x, gold):
if y < 0 or y >= m or x < 0 or x >= n or grid[y][x] == 0:
return gold
gold += grid[y][x]
origin, grid[y][x] = grid[y][x], 0
maxGold = 0
... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR ASSIGN... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
def dfs(i: int, j: int, sum: int, seen: set) -> int:
mx = sum
for x, y in ((i, j + 1), (i, j - 1), (i + 1, j), (i - 1, j)):
if not (
x < 0
or x >= m
... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
out = 0
for y, row in enumerate(grid):
for x, val in enumerate(row):
if val != 0:
cur_max = max_collect(x, y, grid)
out = max(out, cur_max)
return out
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF FUNC_CALL VAR LIST IF VAR NUMBER VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR NUMBER VAR FUNC_CALL VAR VA... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
def dfs(i: int, j: int, sum_so_far: int, seen: set) -> int:
if i < 0 or i >= m or j < 0 or j >= n or not grid[i][j] or (i, j) in seen:
return sum_so_far
seen.add((i, j))
sum_so_far +... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FU... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
m = len(grid)
n = len(grid[0])
self.gold = 0
def DFS(i, j):
if i < 0 or i >= m or j < 0 or j >= n:
return 0
if grid[i][j] == 0:
return 0
tmp =... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR BIN_OP ... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
if not grid:
return 0
results = []
for i in range(len(grid)):
for j in range(len(grid[0])):
if grid[i][j] == 0:
continue
tmp = grid[i][j]
... | CLASS_DEF FUNC_DEF VAR VAR VAR IF VAR RETURN NUMBER 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 NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR STRING EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR VAR ... |
In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
Return the maximum amount of gold you can collect under the conditions:
Every time you are located in a cell you will collect all the gold in that cell.
From your position you can wa... | class Solution:
def getMaximumGold(self, grid: List[List[int]]) -> int:
if not grid or not grid[0]:
return 0
r, c = len(grid), len(grid[0])
def dfs(i, j, curr, visited):
self.mx = max(self.mx, curr)
for di, dj in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
... | CLASS_DEF FUNC_DEF VAR VAR VAR IF VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER IF NUMBER BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR... |
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.
A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.
Example:
Input: "23"
Output: ["ad", "ae", "af", "bd", "be", "bf"... | class Solution:
def letterCombinations(self, digits):
if not digits:
return []
MAPPING = ("0", "1", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz")
def directed_combinations(i, partial):
if i == len(digits):
result.append("".join(partial))
... | CLASS_DEF FUNC_DEF IF VAR RETURN LIST ASSIGN VAR STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN FOR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR LIST VAR ASSIGN VAR LIST EXPR FUNC_CAL... |
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.
A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.
Example:
Input: "23"
Output: ["ad", "ae", "af", "bd", "be", "bf"... | class Solution:
def letterCombinations(self, digits):
interpret_digit = {
"1": "",
"2": "abc",
"3": "def",
"4": "ghi",
"5": "jkl",
"6": "mno",
"7": "pqrs",
"8": "tuv",
"9": "wxyz",
"0": "... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR VAR LIST STRING LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR... |
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.
A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.
Example:
Input: "23"
Output: ["ad", "ae", "af", "bd", "be", "bf"... | class Solution:
def letterCombinations(self, digits):
key = {
(2): "abc",
(3): "def",
(4): "ghi",
(5): "jkl",
(6): "mno",
(7): "pqrs",
(8): "tuv",
(9): "wxyz",
}
nonlocal out
out = [""]
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST STRING FUNC_DEF IF VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN... |
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.
A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.
Example:
Input: "23"
Output: ["ad", "ae", "af", "bd", "be", "bf"... | class Solution:
def __init__(self):
self.phone = ["", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"]
def letterCombinations(self, digits):
if not digits:
return []
results = []
self.dfs(digits, results, "", 0)
return results
def dfs(self,... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING FUNC_DEF IF VAR RETURN LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR STRING NUMBER RETURN VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUM... |
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.
A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.
Example:
Input: "23"
Output: ["ad", "ae", "af", "bd", "be", "bf"... | class Solution:
def letterCombinations(self, digits):
def dfs(digits, current, result):
if not digits:
result.append(current)
return
for c in dic[digits[0]]:
dfs(digits[1:], current + c, result)
if not digits:
ret... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR VAR IF VAR RETURN LIST ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST EXPR FUNC_CALL VAR V... |
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.
A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.
Example:
Input: "23"
Output: ["ad", "ae", "af", "bd", "be", "bf"... | class Solution:
def letterCombinations(self, digits):
if digits == None or len(digits) == 0:
return []
res = []
cur = ""
dmap = {}
dmap["0"] = [" "]
dmap["1"] = []
dmap["2"] = ["a", "b", "c"]
dmap["3"] = ["d", "e", "f"]
dmap["4"] =... | CLASS_DEF FUNC_DEF IF VAR NONE FUNC_CALL VAR VAR NUMBER RETURN LIST ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR DICT ASSIGN VAR STRING LIST STRING ASSIGN VAR STRING LIST ASSIGN VAR STRING LIST STRING STRING STRING ASSIGN VAR STRING LIST STRING STRING STRING ASSIGN VAR STRING LIST STRING STRING STRING ASSIGN VAR STRING... |
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.
A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.
Example:
Input: "23"
Output: ["ad", "ae", "af", "bd", "be", "bf"... | class Solution:
def letterCombinations(self, digits):
dic = {
"2": ["a", "b", "c"],
"3": ["d", "e", "f"],
"4": ["g", "h", "i"],
"5": ["j", "k", "l"],
"6": ["m", "n", "o"],
"7": ["p", "q", "r", "s"],
"8": ["t", "u", "v"],
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING LIST STRING STRING STRING LIST STRING STRING STRING LIST STRING STRING STRING LIST STRING STRING STRING LIST STRING STRING STRING LIST STRING STRING STRING STRING LIST STRING STRING STRING LIST STRING STRING STRING STRING IF STRI... |
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.
A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.
Example:
Input: "23"
Output: ["ad", "ae", "af", "bd", "be", "bf"... | class Solution:
def letterCombinations(self, digits):
self.dic = {
"2": "abc",
"3": "def",
"4": "ghi",
"5": "jkl",
"6": "mno",
"7": "pqrs",
"8": "tuv",
"9": "wxyz",
}
if not digits:
r... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING IF VAR RETURN LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER STRING VAR RETURN VAR FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR ... |
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.
A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.
Example:
Input: "23"
Output: ["ad", "ae", "af", "bd", "be", "bf"... | class Solution:
def letterCombinations(self, digits):
if "" == digits:
return []
kvmaps = {
"2": "abc",
"3": "def",
"4": "ghi",
"5": "jkl",
"6": "mno",
"7": "pqrs",
"8": "tuv",
"9": "wxyz",
... | CLASS_DEF FUNC_DEF IF STRING VAR RETURN LIST ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST STRING FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR RETURN VAR |
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.
A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.
Example:
Input: "23"
Output: ["ad", "ae", "af", "bd", "be", "bf"... | class Solution:
Dmap = {
"2": "abc",
"3": "def",
"4": "ghi",
"5": "jkl",
"6": "mno",
"7": "pqrs",
"8": "tuv",
"9": "wxyz",
}
def letterCombinations(self, digits):
if "1" in digits or "0" in digits:
return []
if len(... | CLASS_DEF ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING FUNC_DEF IF STRING VAR STRING VAR RETURN LIST IF FUNC_CALL VAR VAR NUMBER RETURN LIST RETURN FUNC_CALL VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN LIST STRING ASSIGN VAR LIST... |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
l = arr.copy()
i = 0
c = 0
while i < len(arr):
arr[i] = l[c]
arr[i + 1] = l[n // 2 + c]
c += 1
i += 2
return arr | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER RETURN VAR |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
mid = n // 2
a = arr[:mid]
b = arr[mid:]
arr[0::2] = a
arr[1::2] = b
return arr | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER NUMBER VAR RETURN VAR |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
ans = [0] * n
k = 0
for i in range(0, n // 2):
ans[k] = arr[i]
k += 1
ans[k] = arr[n // 2 + i]
k += 1
return ans | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
d = n // 2
for i in range(1, n - 2, 2):
arr.insert(i, arr[d])
arr.pop(d + 1)
d += 1 | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
for i in range(n // 2):
arr.append(arr[i])
arr.append(arr[n // 2 + i])
arr[:] = arr[n:]
return arr | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR RETURN VAR |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
a = arr[: n // 2]
b = arr[n // 2 :]
arr.clear()
for i in range(n // 2):
arr.append(a[i])
arr.append(b[i])
return arr | CLASS_DEF FUNC_DEF ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
half = n // 2
l1 = arr[0:half]
l2 = arr[half:n]
del arr[:]
for i in range(half):
arr.append(l1[i])
arr.append(l2[i]) | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
mid = n // 2
k = mid
i = 1
while mid < n:
arr.insert(i, arr[mid])
arr.pop(mid + 1)
i += 2
mid += 1 | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def r_shuffle(self, arr1, arr2, n, result):
if len(arr1) == len(arr2) == 1:
result.extend([arr1[0], arr2[0]])
else:
m = n // 2
self.r_shuffle(arr1[0:m], arr2[0:m], m, result)
self.r_shuffle(arr1[m:], arr2[m:], len(arr1[m:]), result)
... | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER EXPR FUN... |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
ans = []
mid = n // 2
for i in range(n // 2):
ans.append(arr[i])
ans.append(arr[i + mid])
for i in range(n):
arr[i] = ans[i] | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
if len(arr) == 1:
return 0
else:
if n % 2 == 0:
mini = arr[0 : n // 2]
maxi = arr[n // 2 : n]
arr.clear()
lmin = len(mini)
lmax = len(maxi)
for i i... | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR V... |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
x = len(arr) // 2
y = arr[x:]
z = arr[:x]
ans = []
arr.clear()
for i in range(x):
ans.append(z[i])
ans.append(y[i])
arr.extend(ans)
return arr | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
x = n // 2
l = arr[:x]
r = arr[x:]
flg = 0
j = 0
k = 0
for i in range(n):
if flg == 0:
arr[i] = l[j]
j += 1
flg = 1
else:
a... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
l = []
mid = n / 2
a1 = arr[: int(mid)]
a2 = arr[int(mid) :]
for i in range(len(a2)):
l.append(a1[i])
l.append(a2[i])
for i in range(n):
arr[i] = l[i]
return arr | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
i = 0
p = []
k = len(arr) // 2
j = k
while j < n and i < k:
p.append(arr[i])
p.append(arr[j])
i += 1
j += 1
a[:] = p | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
l = []
k = arr[: n // 2]
j = arr[n // 2 :]
for i in range(len(k)):
l.append(k[i])
l.append(j[i])
for i in range(n):
arr[i] = l[i] | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
a2 = []
for k in range(int(n / 2)):
a2.append(arr[k])
a2.append(arr[int(n / 2 + k)])
i = 0
for k in a2:
arr[i] = k
i += 1 | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
a = []
b = []
for i in range(n):
if i < n // 2:
a.append(arr[i])
elif i >= n // 2:
b.append(arr[i])
r = []
for k in range(n // 2):
r.append(a[k])
r... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
a = list()
b = list()
for i in range(0, int(n / 2)):
a.append(arr[i])
for i in range(int(n / 2), n):
b.append(arr[i])
for i in range(0, n):
if i % 2 == 0:
arr[i] = a[int(i / 2... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VA... |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
def _solve(L, R):
if R - L <= 1:
return
M = R - L + 1
h = M // 2
hh = h // 2
if h % 2:
i, j, pv = L + hh, L + h, arr[L + h - 1]
while i < L + h - 1:
... | CLASS_DEF FUNC_DEF FUNC_DEF IF BIN_OP VAR VAR NUMBER RETURN ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VA... |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
p = n // 2
for i in range(0, p):
t = arr.pop(0)
arr.append(t)
r = arr.pop(p - i - 1)
arr.append(r)
return arr | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
m = n // 2
l = []
l1 = []
for i in range(m):
l.append(arr[i])
for i in range(m, n):
l1.append(arr[i])
arr[::2] = l[:]
arr[1::2] = l1[:]
return arr | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER VAR RETURN VAR |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
mid = n // 2
p = []
first = 0
second = n // 2
for index in range(n):
if index % 2 == 0:
p.append(arr[first])
first += 1
else:
p.append(arr[second])
... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
k = n // 2
a = []
for i in range(n // 2):
a.append(arr[i])
a.append(arr[i + k])
for i in range(0, n):
arr[i] = a[i]
return arr | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR RETURN VAR |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
l = len(arr)
p = [0] * l
for i in range(l):
if i < l // 2:
pos = i
pos = 2 * pos
p[pos] = arr[i]
else:
pos = i
pos = 2 * (pos - n) + 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR AS... |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
lis = []
s, m = 0, len(arr) // 2
while s < len(arr) // 2:
lis.append(arr[s])
lis.append(arr[m])
s += 1
m += 1
for i in range(len(arr)):
arr[i] = lis[i] | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
a = arr[0 : n // 2]
b = arr[n // 2 :]
c1 = 0
c2 = 0
for i in range(n):
if i % 2 == 0:
arr[i] = a[c1]
c1 += 1
else:
arr[i] = b[c2]
c2 += 1 | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
t = n // 2
if n % 2 != 0:
t = t + 1
l = arr[:t]
f = arr[t:]
if n % 2 != 0:
k = 0
for i in range(0, t - 1):
arr[k] = l[i]
arr[k + 1] = f[i]
k = ... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NU... |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
center, odd_condition = (n // 2, 1) if n % 2 == 0 else (n // 2 + 1, 0)
b1_array = arr[center:]
a1_array = arr[:center]
a1_count = 0
b1_count = 0
for i in range(n):
if i % 2 == 0:
arr[i] = a1_... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
k = list(arr)
a = 1
b = len(k) // 2
for i in range(1, len(arr) - 1, 2):
arr[i] = k[b]
arr[i + 1] = k[a]
b += 1
a += 1 | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
i = 0
mid = n // 2
j = mid
arr1 = [0] * n
m = 0
while i < mid and j < n:
arr1[m] = arr[i]
i += 1
m += 1
arr1[m] = arr[j]
j += 1
m += 1
for ... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
a = len(arr)
for i in range(1, a, 2):
arr.insert(i, None)
for i in range(a // 2):
arr[2 * i + 1] = arr[a + i]
for i in range(a // 2):
arr.pop()
return arr | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NONE FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR RETURN VAR |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
x = 0
def solve(self, i, arr, n):
if i == n // 2 - 1:
return
a = arr[i - n // 2]
b = arr[i]
self.solve(i - 1, arr, n)
arr[i - n // 2 + self.x] = a
arr[i - n // 2 + 1 + self.x] = b
self.x += 1
def shuffleArray(self, arr, n)... | CLASS_DEF ASSIGN VAR NUMBER FUNC_DEF IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR N... |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
b = arr[0 : n // 2]
c = arr[n // 2 : len(arr)]
d = []
for i in range(len(b)):
d.append(b[i])
d.append(c[i])
for i in range(len(arr)):
arr[i] = d[i]
return arr | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
arr1 = arr[: n // 2]
arr2 = arr[n // 2 :]
arr[::2] = arr1
arr[1::2] = arr2
return arr | CLASS_DEF FUNC_DEF ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER VAR RETURN VAR |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
d = []
d += arr
arr.clear()
for i in range(n // 2):
arr.append(d[i])
arr.append(d[i + n // 2]) | CLASS_DEF FUNC_DEF ASSIGN VAR LIST VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
arr1 = arr[: n // 2]
arr2 = arr[n // 2 :]
for i in range(n):
if i % 2 == 0:
arr[i] = arr1.pop(0)
elif i % 2 == 1:
arr[i] = arr2.pop(0)
arr.append("")
return arr | CLASS_DEF FUNC_DEF ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN VAR |
Given an array arr[] of n elements in the following format {a1, a2, a3, a4, .., an/2, b1, b2, b3, b4, ., bn/2}, the task is shuffle the array to {a1, b1, a2, b2, a3, b3, , an/2, bn/2} without using extra space.
Example 1:
Input: n = 4, arr[] = {1, 2, 9, 15}
Output: 1 9 2 15
Explanation: a1=1 , a2=2 , b1=9 , b2=15
So t... | class Solution:
def shuffleArray(self, arr, n):
res = []
l = 0
r = n // 2
for i in range(n):
if i % 2 == 0:
res.append(arr[l])
l += 1
else:
res.append(arr[r])
r += 1
for i in range(n):
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.