description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
class Solution: def longestPath( self, mat, n: int, m: int, xs: int, ys: int, xd: int, yd: int ) -> int: ans = -1 dx = [1, -1, 0, 0] dy = [0, 0, 1, -1] def rec(i, j, path=0): nonlocal ans, xd, yd if i < 0 or j < 0 or i >= n or j >= m: ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER FUNC_DEF NUMBER IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR RETURN IF VAR VAR VAR NUMBER RETURN IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN ASSIGN VAR VAR VAR ...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
class Solution: def __longestPathHelper(self, matrix, path, n, m, x, y, xd, yd): self.visited.add((x, y)) for x_offset, y_offset in self.dirs: temp_x, temp_y = x + x_offset, y + y_offset if ( 0 <= temp_x < n and 0 <= temp_y < m ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF NUMBER VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
class Solution: def longestPath(self, mat, n, m, xs, ys, xd, yd): def solve(mat, n, m, xs, ys, xd, yd, count=0): if mat[xd][yd] == 0: return -1 if xs == xd and ys == yd: return count if xs < 0 or xs >= n or ys < 0 or ys >= m: ...
CLASS_DEF FUNC_DEF FUNC_DEF NUMBER IF VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR VAR VAR RETURN VAR IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR RETURN NUMBER IF VAR VAR VAR LIST NUMBER NUMBER RETURN NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VA...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
class Solution: def longestPath(self, mat, n, m, xs, ys, xd, yd): def function(i, j, visited, mat, sum1, sum2): if i < 0 or j < 0 or i >= len(mat) or j >= len(mat[0]) or mat[i][j] == 0: return if visited[i][j] == "T": return if i == xd an...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER RETURN IF VAR VAR VAR STRING RETURN IF VAR VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR RETURN ASSIGN VAR VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR VA...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
class Solution: def longestPath(self, mat, n: int, m: int, xs: int, ys: int, xd: int, yd: int): ans = -1 dir_x = [0, 0, 1, -1] dir_y = [1, -1, 0, 0] def isvalid(mat, n, m, xs, ys): if xs < 0 or ys < 0: return False if xs >= n or ys >= m: ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR VAR VAR ASSIGN VAR F...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
def backtracking(xs, ys, n, m, xd, yd, arr): if arr[xs][ys] == 0 or arr[xd][yd] == 0: return -1 vis = set() vis.add((xs, ys)) res = [] helper(xs, ys, n, m, xd, yd, arr, vis, res) if res: return res[-1] - 1 return -1 def helper(i, j, r, c, xd, yd, arr, vis, res): if (i, ...
FUNC_DEF IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR RETURN BIN_OP VAR NUMBER NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN V...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
class Solution: def longestPath( self, mat, n: int, m: int, xs: int, ys: int, xd: int, yd: int ) -> int: def check(mat, n, m, i, j, vis): if i >= 0 and j >= 0 and i < n and j < m and vis[i][j] == 0: return True return False def recur(mat, n, m, ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR FUNC_DEF IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
class Solution: def longestPath(self, mat, n, m, xs, ys, xd, yd): if mat[xs][ys] == 0: return -1 self.mat = mat self.n = n self.m = m self.ans = 0 self.xd = xd self.yd = yd self.move(xs, ys, 1, {(xs, ys): 1}) return self.ans - 1 ...
CLASS_DEF FUNC_DEF IF VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER DICT VAR VAR NUMBER RETURN BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN FOR VAR VAR LIST BIN_OP V...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
class Solution: def longestPath( self, mat, n: int, m: int, xs: int, ys: int, xd: int, yd: int ) -> int: if mat[xs][ys] == 0 or mat[xd][yd] == 0: return -1 res = [0] def dfs(r, c, path): if r == xd and c == yd: res[0] = max(res[0], path) ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR LIST NUMBER FUNC_DEF IF VAR VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR RETURN ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
class Solution: def longestPath( self, mat, n: int, m: int, xs: int, ys: int, xd: int, yd: int ) -> int: visited = [[(0) for i in range(m)] for i in range(n)] ds = "" ans = [-1] xMoves = [1, 0, 0, -1] yMoves = [0, 1, -1, 0] dir = "DLRU" def solve...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR STRING FUNC_DEF IF VAR VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMB...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
class Solution: def longestPath( self, mat, n: int, m: int, xs: int, ys: int, xd: int, yd: int ) -> int: ans = -1 def dfs(x, y, visited, dist): nonlocal ans if mat[x][y] == 0 or (x, y) in visited: return if (x, y) == (xd, yd): ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR VAR NUMBER VAR VAR VAR RETURN IF VAR VAR VAR VAR 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 ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VA...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
def rec(mat, i, j, visited, xd, yd): if ( i < 0 or j < 0 or i >= len(mat) or j >= len(mat[0]) or visited[i][j] or not mat[i][j] ): return -1 if i == xd and j == yd: return 0 visited[i][j] = True x = [0, 0, 1, -1] y = [1, -1, 0, 0] ...
FUNC_DEF IF VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASS...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
class Solution: def longestPath( self, mat, n: int, m: int, xs: int, ys: int, xd: int, yd: int ) -> int: ans = -1 def dfs(x, y, visited, dist): nonlocal ans if mat[x][y] == 0 or (x, y) in visited: return if (x, y) == (xd, yd): ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR VAR NUMBER VAR VAR VAR RETURN IF VAR VAR VAR VAR 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 ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VA...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
class Solution: def longestPath(self, mat, n, m, xs, ys, xd, yd): if mat[xs][ys] == 0 or mat[xd][yd] == 0: return -1 path = [(1, 0), (-1, 0), (0, 1), (0, -1)] visit = [([0] * m) for i in range(n)] def f(i, j, count): nonlocal maxi if i == xd and ...
CLASS_DEF FUNC_DEF IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN FOR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
class Solution: def longestPath(self, mat, n, m, xs, ys, xd, yd): if mat[xs][ys] == 0 or mat[xd][yd] == 0: return -1 def fun(i, j): if i == xd and j == yd: return 0 if i < 0 or i >= n or j < 0 or j >= m or mat[i][j] == 0: return f...
CLASS_DEF FUNC_DEF IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR VAR VAR RETURN NUMBER IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER RETURN FUNC_CALL VAR STRING ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR B...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
class Solution: def longestPath(self, mat, n, m, xs, ys, xd, yd): def haha(arr, i, j, p, q): if i == p and j == q: return 0 if i < 0 or j < 0 or i >= n or j >= m or arr[i][j] == 0: return float("-inf") ma = arr[i][j] arr[i][j]...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR VAR VAR RETURN NUMBER IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSI...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
class Solution: def longestPath( self, matrix, n: int, m: int, xs: int, ys: int, xd: int, yd: int ) -> int: if matrix[xs][ys] == 0 or matrix[xd][yd] == 0: return -1 visited = [[(False) for _ in range(len(matrix[0]))] for _ in range(len(matrix))] self.res = 0 ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER VAR VAR ...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
class Solution: def longestPath(self, mat, n, m, xs, ys, xd, yd): ans = -1 if mat[xs][ys] == 0 or mat[xd][yd] == 0: return -1 def fun(i, j, path): nonlocal ans mat[i][j] = 2 if i == xd and j == yd: ans = max(ans, path) ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMB...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
class Solution: def longestPath(self, mat, n, m, xs, ys, xd, yd): def haha(arr, i, j, p, q): if i == p and j == q: return 0 if i < 0 or j < 0 or i >= n or j >= m or arr[i][j] == 0: return float("-inf") ma = arr[i][j] arr[i][j]...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR VAR VAR RETURN NUMBER IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSI...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
class Solution: def longestPath( self, mat, n: int, m: int, xs: int, ys: int, xd: int, yd: int ) -> int: paths = [] path = [] recStack = set() recStack.add((xs, ys)) def dfs(r, c): if mat[r][c] == 0: return if [r, c] == [x...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR VAR VAR NUMBER RETURN IF LIST VAR VAR LIST VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR VAR...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
class Solution: def longestPath(self, mat, n, m, xs: int, ys: int, xd: int, yd: int) -> int: if not mat: return mat if mat[xs][ys] == 0: return -1 visited = set() rows, cols = len(mat), len(mat[0]) ans = [] visited = set() def dfs(i, ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR IF VAR RETURN VAR IF VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NU...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
class Solution: def utils( self, mat, n, m, src_row, src_col, dest_row, dest_col, max_path, cur_path ): if src_col == dest_col and src_row == dest_row: max_path[0] = max(max_path[0], path) return 0 if ( (src_col >= m or src_row >= n) or (s...
CLASS_DEF FUNC_DEF IF VAR VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR RETURN NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP ...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
class Solution: def is_safe(self, x, y, r, c, mat): global vis if x < 0 or x >= r or y < 0 or y >= c: return False return mat[x][y] == 1 and vis[x][y] == False def bt(self, cur_x, cur_y, xd, yd, r, c, dist, mat): global ans, vis if cur_x == xd and cur_y == y...
CLASS_DEF FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR RETURN NUMBER RETURN VAR VAR VAR NUMBER VAR VAR VAR NUMBER FUNC_DEF IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL V...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
class Solution: def longestPath(self, mat, n, m, xs, ys, xd, yd): self.ans = -1 self.dir_delta = [[0, -1], [-1, 0], [0, 1], [1, 0]] R = n C = m def canGoto(r, c): nonlocal mat, R, C return 0 <= r < R and 0 <= c < C and mat[r][c] == 1 def bac...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF RETURN NUMBER VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER FUNC_DEF NUMBER IF FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASS...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
class Solution: def longestPath(self, mat, n, m, xs, ys, xd, yd): if mat[xs][ys] == 0: return -1 vis = [[(False) for _ in range(m)] for _ in range(n)] mat[xs][ys] = -1 mx = [-1] self.fn(mat, n, m, xs, ys, xd, yd, 0, vis, mx) return max(mx) def fn(sel...
CLASS_DEF FUNC_DEF IF VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR RETURN FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR V...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
class Solution: def isValid(self, mat, x, y, n, m): if x >= 0 and y >= 0 and x < n and y < m and not vis[x][y] and mat[x][y]: return True return False def solve(self, mat, n, m, x, y, ex, ey, cor, steps): global maxi if not self.isValid(mat, x, y, n, m): ...
CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF IF FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSI...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
class Solution: def longestPath( self, mat, n: int, m: int, xs: int, ys: int, xd: int, yd: int ) -> int: def solve(mat, n, m, xs, ys, xd, yd, temp): if ( xs < 0 or ys < 0 or xs == n or ys == m or mat[xs...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR FUNC_DEF IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN IF VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VA...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
class Solution: def __init__(self): self.ans = -1 def longestPath(self, mat, n: int, m: int, xs: int, ys: int, xd: int, yd: int): rows = len(mat) cols = len(mat[0]) v2 = [[(False) for _ in range(cols)] for _ in range(rows)] self.path(xs, ys, xd, yd, mat, v2, 0) ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FUNC_DEF VAR VAR VAR VAR VAR VAR 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 EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF IF VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR FU...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
class Solution: def longestPath(self, mat, n, m, xs, ys, xd, yd): ans = [] visited = [[(0) for _ in range(m)] for _ in range(n)] def isSafe(x, y): if ( x >= 0 and y >= 0 and x < n and y < m and visi...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
class Solution: def longestPath( self, mat, n: int, m: int, xs: int, ys: int, xd: int, yd: int ) -> int: return ( self.helper(mat, xs, ys, n - 1, m - 1, (xd, yd), 0) if mat[xs][ys] else -1 ) def helper(self, grid, x, y, n, m, end, count): if (x, y) == end: ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR RETURN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER NUMBER VAR FUNC_DEF IF VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CA...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
class Solution: def longestPath(self, mat, n, m, xs, ys, xd, yd): path_lengths = [] visited = set() pos = xs, ys dst = xd, yd length = 0 self.dfs(mat, n, m, pos, dst, visited, length, path_lengths) if len(path_lengths) == 0: return -1 retu...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR NUMBER VAR NUMBER NUMBER RETURN IF VAR VAR RETURN IF VAR VAR EXPR ...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
class Solution: def longestPath( self, mat, n: int, m: int, xs: int, ys: int, xd: int, yd: int ) -> int: ans = [-1] def f(x, y, xd, yd, mat, n, m, vis, ans, path): if x < 0 or x >= n or y < 0 or y >= m or vis[x][y] or mat[x][y] == 0: return if x ...
CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST NUMBER FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN IF VAR VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR RETURN ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VA...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
class Solution: def longestPath(self, mat, n, m, xs, ys, xd, yd): if mat[xs][ys] == 0 or mat[xd][yd] == 0: return -1 visited = [([-1] * len(mat[0])) for i in range(len(mat))] def traverse(i, j, xd, yd): if ( i < 0 or j < 0 ...
CLASS_DEF FUNC_DEF IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL 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 NUMBER IF VAR VAR VAR VAR...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
def util(mat, m, n, xs, ys, xd, yd, visit, path): if xs == xd and ys == yd: return path if xs < 0 or xs >= m or ys < 0 or ys >= n or mat[xs][ys] == 0 or visit[xs][ys]: return float("inf") visit[xs][ys] = True dx = [0, 0, 1, -1] dy = [1, -1, 0, 0] dist = 0 for i in range(4): ...
FUNC_DEF IF VAR VAR VAR VAR RETURN VAR IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR VAR VAR RETURN FUNC_CALL VAR STRING ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_O...
Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possible from source(xs,ys) to a destination(xd,yd) within the matrix. We are allowed to move to only adjacent cells which are not hurdles. The route cannot contain any diagonal moves and a loc...
class Solution: def longestPath(self, mat, n, m, xs, ys, xd, yd): n = len(mat) m = len(mat[0]) ans = -1 def dfs(i, j, visited, dist): nonlocal ans move = [[-1, 0], [1, 0], [0, -1], [0, 1]] if mat[i][j] == 0 or (i, j) in visited: r...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR RETURN IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN EXPR FUNC_CALL VA...
Given a sorted array Arr of size N and a number X, you need to find the number of occurrences of X in Arr. Example 1: Input: N = 7, X = 2 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 4 Explanation: 2 occurs 4 times in the given array. Example 2: Input: N = 7, X = 4 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 0 Explanation: 4 is not...
class Solution: def l_find_bsearch(self, nums, target): l = 0 r = len(nums) - 1 while l <= r: mid = (l + r) // 2 if nums[mid] == target: r = mid - 1 if nums[mid] < target: l = mid + 1 if nums[mid] > target: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_O...
Given a sorted array Arr of size N and a number X, you need to find the number of occurrences of X in Arr. Example 1: Input: N = 7, X = 2 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 4 Explanation: 2 occurs 4 times in the given array. Example 2: Input: N = 7, X = 4 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 0 Explanation: 4 is not...
class Solution: def count(self, arr, n, x): count = 0 i = 0 while i < n: if arr[i] == x: count += 1 i += 1 return count
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR
Given a sorted array Arr of size N and a number X, you need to find the number of occurrences of X in Arr. Example 1: Input: N = 7, X = 2 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 4 Explanation: 2 occurs 4 times in the given array. Example 2: Input: N = 7, X = 4 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 0 Explanation: 4 is not...
class Solution: def count1(self, nums, n, x): count = 0 for num in nums: if num == x: count += 1 return count def count(self, nums, n, x): def binarySearch(left, right, searchDirection): result = -1 while left <= right: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VA...
Given a sorted array Arr of size N and a number X, you need to find the number of occurrences of X in Arr. Example 1: Input: N = 7, X = 2 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 4 Explanation: 2 occurs 4 times in the given array. Example 2: Input: N = 7, X = 4 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 0 Explanation: 4 is not...
class Solution: def count(self, arr, n, x): l = 0 r = n - 1 left = -1 while l <= r: mid = (l + r) // 2 if arr[mid] == x: left = mid r = mid - 1 elif arr[mid] > x: r = mid - 1 else: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASS...
Given a sorted array Arr of size N and a number X, you need to find the number of occurrences of X in Arr. Example 1: Input: N = 7, X = 2 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 4 Explanation: 2 occurs 4 times in the given array. Example 2: Input: N = 7, X = 4 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 0 Explanation: 4 is not...
class Solution: def binary(self, arr, n, x): s = 0 e = len(arr) - 1 while s <= e: m = (s + e) // 2 if arr[m] == x: return m elif arr[m] < x: s = m + 1 else: e = m - 1 return -1 def c...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER...
Given a sorted array Arr of size N and a number X, you need to find the number of occurrences of X in Arr. Example 1: Input: N = 7, X = 2 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 4 Explanation: 2 occurs 4 times in the given array. Example 2: Input: N = 7, X = 4 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 0 Explanation: 4 is not...
class Solution: def count(self, arr, n, x): def first(arr, n, x): low = 0 high = n - 1 s = -1 while low <= high: mid = low + (high - low) // 2 if arr[mid] < x: low = mid + 1 elif arr[mid] > ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR...
Given a sorted array Arr of size N and a number X, you need to find the number of occurrences of X in Arr. Example 1: Input: N = 7, X = 2 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 4 Explanation: 2 occurs 4 times in the given array. Example 2: Input: N = 7, X = 4 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 0 Explanation: 4 is not...
class Solution: def count(self, arr, n, x): def search(last=False): res = -1 low, high = 0, n - 1 while low <= high: mid = (low + high) // 2 if arr[mid] == x: res = mid if last: ...
CLASS_DEF FUNC_DEF FUNC_DEF NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR IF VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETUR...
Given a sorted array Arr of size N and a number X, you need to find the number of occurrences of X in Arr. Example 1: Input: N = 7, X = 2 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 4 Explanation: 2 occurs 4 times in the given array. Example 2: Input: N = 7, X = 4 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 0 Explanation: 4 is not...
class Solution: def count(self, arr, n, x): first = -1 last = -1 count = 0 for i in range(n): if arr[i] == x: first = i break if first == -1: return 0 for i in range(n - 1, -1, -1): if arr[i] == x: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR
Given a sorted array Arr of size N and a number X, you need to find the number of occurrences of X in Arr. Example 1: Input: N = 7, X = 2 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 4 Explanation: 2 occurs 4 times in the given array. Example 2: Input: N = 7, X = 4 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 0 Explanation: 4 is not...
class Solution: def count(self, arr, n, x): n = len(arr) first = -1 last = -1 low = 0 high = n - 1 while low <= high: mid = (low + high) // 2 if (mid == 0 or x > arr[mid - 1]) and arr[mid] == x: first = mid brea...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NU...
Given a sorted array Arr of size N and a number X, you need to find the number of occurrences of X in Arr. Example 1: Input: N = 7, X = 2 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 4 Explanation: 2 occurs 4 times in the given array. Example 2: Input: N = 7, X = 4 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 0 Explanation: 4 is not...
class Solution: def count(self, arr, n, x): if n <= 0: return -1 elif x not in arr: return 0 else: c = 0 for i in arr: if i == x: c += 1 return c
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR
Given a sorted array Arr of size N and a number X, you need to find the number of occurrences of X in Arr. Example 1: Input: N = 7, X = 2 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 4 Explanation: 2 occurs 4 times in the given array. Example 2: Input: N = 7, X = 4 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 0 Explanation: 4 is not...
class Solution: def count(self, arr, n, x): start = 0 end = n - 1 while start <= end: if arr[start] != x: start = start + 1 if arr[end] != x: end = end - 1 if arr[start] == x and arr[end] == x: break ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR IF VAR VAR RETURN BIN_OP BIN_OP VAR VAR NUMBER RETURN NUMBER
Given a sorted array Arr of size N and a number X, you need to find the number of occurrences of X in Arr. Example 1: Input: N = 7, X = 2 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 4 Explanation: 2 occurs 4 times in the given array. Example 2: Input: N = 7, X = 4 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 0 Explanation: 4 is not...
class Solution: def count(self, arr, n, x): if x not in arr: return 0 l = 0 r = len(arr) - 1 while arr[l] != x: l = l + 1 while arr[r] != x: r = r - 1 return r - l + 1
CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER
Given a sorted array Arr of size N and a number X, you need to find the number of occurrences of X in Arr. Example 1: Input: N = 7, X = 2 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 4 Explanation: 2 occurs 4 times in the given array. Example 2: Input: N = 7, X = 4 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 0 Explanation: 4 is not...
class Solution: def count(self, arr, n, x): l = 0 r = n - 1 c = 0 last = -1 first = -1 while l <= r: mid = (l + r) // 2 if arr[mid] == x: first = mid l = mid + 1 elif arr[mid] < x: l ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUM...
Given a sorted array Arr of size N and a number X, you need to find the number of occurrences of X in Arr. Example 1: Input: N = 7, X = 2 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 4 Explanation: 2 occurs 4 times in the given array. Example 2: Input: N = 7, X = 4 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 0 Explanation: 4 is not...
class Solution: def count(self, arr, n, x): d = {} for i in arr: if i in d: d[i] += 1 else: d[i] = 1 c = 0 for i in d: if i == x: return d[i] break else: c...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR RETURN VAR VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER
Given a sorted array Arr of size N and a number X, you need to find the number of occurrences of X in Arr. Example 1: Input: N = 7, X = 2 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 4 Explanation: 2 occurs 4 times in the given array. Example 2: Input: N = 7, X = 4 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 0 Explanation: 4 is not...
class Solution: def count(self, arr, n, x): left = 0 right = len(arr) - 1 f = 1 w = 1 while left <= right: mid = (left + right) // 2 if arr[mid] == x: w = 0 k = mid while k >= 1 and arr[k] == arr[k - 1]:...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VA...
Given a sorted array Arr of size N and a number X, you need to find the number of occurrences of X in Arr. Example 1: Input: N = 7, X = 2 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 4 Explanation: 2 occurs 4 times in the given array. Example 2: Input: N = 7, X = 4 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 0 Explanation: 4 is not...
class Solution: def count(self, arr, n, x): i, j = 0, n - 1 while i <= j: m = (i + j) // 2 if arr[m] >= x: j = m - 1 else: i = m + 1 if i < 0 or i >= n or arr[i] != x: return 0 f = i i, j = 0, n ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP...
Given a sorted array Arr of size N and a number X, you need to find the number of occurrences of X in Arr. Example 1: Input: N = 7, X = 2 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 4 Explanation: 2 occurs 4 times in the given array. Example 2: Input: N = 7, X = 4 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 0 Explanation: 4 is not...
class Solution: def bin_search(self, flag, l, r, nums, target): ans = -1 while l <= r: mid = (l + r) // 2 if nums[mid] < target: l = mid + 1 elif nums[mid] > target: r = mid - 1 else: ans = mid ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_...
Given a sorted array Arr of size N and a number X, you need to find the number of occurrences of X in Arr. Example 1: Input: N = 7, X = 2 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 4 Explanation: 2 occurs 4 times in the given array. Example 2: Input: N = 7, X = 4 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 0 Explanation: 4 is not...
class Solution: def count(self, arr, n, x): s = 0 mid = -1 e = n - 1 while s <= e: mid = s + (e - s) // 2 if arr[mid] == x: break elif arr[mid] > x: e = mid - 1 else: s = mid + 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR V...
Given a sorted array Arr of size N and a number X, you need to find the number of occurrences of X in Arr. Example 1: Input: N = 7, X = 2 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 4 Explanation: 2 occurs 4 times in the given array. Example 2: Input: N = 7, X = 4 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 0 Explanation: 4 is not...
class Solution: def count(self, arr, n, x): l, r = 0, n - 1 count = 0 while l <= r: mid = (l + r) // 2 if arr[mid] == x: count += 1 i, j = mid, mid while i - 1 >= 0 and arr[i - 1] == x: count += 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR WHILE BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER WHILE BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR NUM...
Given a sorted array Arr of size N and a number X, you need to find the number of occurrences of X in Arr. Example 1: Input: N = 7, X = 2 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 4 Explanation: 2 occurs 4 times in the given array. Example 2: Input: N = 7, X = 4 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 0 Explanation: 4 is not...
class Solution: def count(self, arr, n, x): mydict = dict() for i in range(n): if arr[i] not in mydict: mydict[arr[i]] = 1 else: mydict[arr[i]] += 1 if x in mydict: return mydict[x] else: return 0
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR RETURN VAR VAR RETURN NUMBER
Given a sorted array Arr of size N and a number X, you need to find the number of occurrences of X in Arr. Example 1: Input: N = 7, X = 2 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 4 Explanation: 2 occurs 4 times in the given array. Example 2: Input: N = 7, X = 4 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 0 Explanation: 4 is not...
class Solution: def count(self, arr, n, x): left = 0 right = n - 1 while left <= right: mid = (left + right) // 2 if arr[mid] == x: result = [mid, mid] while ( result[0] >= 0 and arr[result[0]] =...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR LIST VAR VAR WHILE VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER NUMBER VAR NUMBER NUMBER WHILE VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR N...
Given a sorted array Arr of size N and a number X, you need to find the number of occurrences of X in Arr. Example 1: Input: N = 7, X = 2 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 4 Explanation: 2 occurs 4 times in the given array. Example 2: Input: N = 7, X = 4 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 0 Explanation: 4 is not...
class Solution: def count(self, arr, n, x): if n == 1: if x == arr[0]: return 1 l = 0 r = n - 1 while l < r: if arr[l] != x: l = l + 1 if arr[r] != x: r = r - 1 if arr[r] == x and arr[l] ...
CLASS_DEF FUNC_DEF IF VAR NUMBER IF VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR RETURN BIN_OP BIN_OP VAR VAR NUMBER RETURN NUMBER
Given a sorted array Arr of size N and a number X, you need to find the number of occurrences of X in Arr. Example 1: Input: N = 7, X = 2 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 4 Explanation: 2 occurs 4 times in the given array. Example 2: Input: N = 7, X = 4 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 0 Explanation: 4 is not...
class Solution: def count(self, arr, n, x): res = [] for i in range(n): if arr[i] == x: res.append(i) if len(res) != 0: return len(res) else: return 0
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR RETURN NUMBER
Given a sorted array Arr of size N and a number X, you need to find the number of occurrences of X in Arr. Example 1: Input: N = 7, X = 2 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 4 Explanation: 2 occurs 4 times in the given array. Example 2: Input: N = 7, X = 4 Arr[] = {1, 1, 2, 2, 2, 2, 3} Output: 0 Explanation: 4 is not...
class Solution: def count(self, arr, n, x): def rhs(arr, x): low = 0 high = len(arr) - 1 while low <= high: mid = (low + high) // 2 if arr[mid] > x: high = mid - 1 else: low = mid + ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VA...
There are $5$ cities in the country. The map of the country is given below. The tour starts from the red city. Each road is associated with a character. Initially, there is an empty string. Every time a road has been travelled the character associated gets appended to the string. At the green city either the string ca...
for _ in range(int(input())): n = input() if len(n) >= 4: if n[-4:] == "1000": print("YES") else: print("NO") else: print("NO")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
There are $5$ cities in the country. The map of the country is given below. The tour starts from the red city. Each road is associated with a character. Initially, there is an empty string. Every time a road has been travelled the character associated gets appended to the string. At the green city either the string ca...
adj = [[0, 1], [2, 1], [3, 1], [4, 1], [0, 1]] T = int(input()) for _ in range(T): L = list(input()) M = [int(x) for x in L] initial = 0 for i in range(len(M)): a = int(M[i]) initial = adj[initial][a] if initial == 4: print("YES") else: print("NO")
ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR...
There are $5$ cities in the country. The map of the country is given below. The tour starts from the red city. Each road is associated with a character. Initially, there is an empty string. Every time a road has been travelled the character associated gets appended to the string. At the green city either the string ca...
def Helper(index, S, adj, root): if index == len(S) and root == 4: return True if index >= len(S): return False ans = False for node in adj[root]: if node[1] == S[index]: ans = ans | Helper(index + 1, S, adj, node[0]) else: pass return ans de...
FUNC_DEF IF VAR FUNC_CALL VAR VAR VAR NUMBER RETURN NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER RETURN VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING RE...
There are $5$ cities in the country. The map of the country is given below. The tour starts from the red city. Each road is associated with a character. Initially, there is an empty string. Every time a road has been travelled the character associated gets appended to the string. At the green city either the string ca...
t = int(input()) for i in range(t): s = str(input()) n = len(s) if n < 4: print("NO") elif s[n - 4] != "0" and s[n - 3] == "0" and s[n - 2] == "0" and s[n - 1] == "0": print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EX...
There are $5$ cities in the country. The map of the country is given below. The tour starts from the red city. Each road is associated with a character. Initially, there is an empty string. Every time a road has been travelled the character associated gets appended to the string. At the green city either the string ca...
for _ in range(int(input())): map = [[0, 1], [2, 1], [3, 1], [4, 1], [0, 1]] path = input() curr = 0 for p in path: curr = map[curr][int(p)] if curr == 4: print("YES") else: print("NO")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
There are $5$ cities in the country. The map of the country is given below. The tour starts from the red city. Each road is associated with a character. Initially, there is an empty string. Every time a road has been travelled the character associated gets appended to the string. At the green city either the string ca...
graph = [ {"0": 0, "1": 1}, {"1": 1, "0": 2}, {"0": 3, "1": 1}, {"1": 1, "0": 4}, {"1": 1, "0": 0}, ] for i in range(0, int(input())): S = input() N = len(S) currentIndex = 0 for i in range(0, N): currentIndex = graph[currentIndex][S[i]] if currentIndex == 4: prin...
ASSIGN VAR LIST DICT STRING STRING NUMBER NUMBER DICT STRING STRING NUMBER NUMBER DICT STRING STRING NUMBER NUMBER DICT STRING STRING NUMBER NUMBER DICT STRING STRING NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FU...
There are $5$ cities in the country. The map of the country is given below. The tour starts from the red city. Each road is associated with a character. Initially, there is an empty string. Every time a road has been travelled the character associated gets appended to the string. At the green city either the string ca...
t = int(input()) for _ in range(t): n = input() if len(n) < 4: print("NO") elif n[-1] == "0" and n[-2] == "0" and n[-3] == "0" and n[-4] == "1": print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
There are $5$ cities in the country. The map of the country is given below. The tour starts from the red city. Each road is associated with a character. Initially, there is an empty string. Every time a road has been travelled the character associated gets appended to the string. At the green city either the string ca...
def state(country, roa): road = int(roa) if country == "red": if road == 0: return "red" else: return "blue" elif country == "blue": if road == 1: return "blue" else: return "yellow" elif country == "yellow": if road...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR NUMBER RETURN STRING RETURN STRING IF VAR STRING IF VAR NUMBER RETURN STRING RETURN STRING IF VAR STRING IF VAR NUMBER RETURN STRING RETURN STRING IF VAR STRING IF VAR NUMBER RETURN STRING RETURN STRING IF VAR STRING IF VAR NUMBER RETURN STRING RETURN STRING FO...
There are $5$ cities in the country. The map of the country is given below. The tour starts from the red city. Each road is associated with a character. Initially, there is an empty string. Every time a road has been travelled the character associated gets appended to the string. At the green city either the string ca...
from sys import stdin for _ in range(int(stdin.readline())): s = stdin.readline().strip() cond = True n = len(s) state = 1 for i in range(n): if s[i] == "0": if state != 1 or state != 5: state += 1 elif state == 5: state -= 4 e...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR ...
There are $5$ cities in the country. The map of the country is given below. The tour starts from the red city. Each road is associated with a character. Initially, there is an empty string. Every time a road has been travelled the character associated gets appended to the string. At the green city either the string ca...
def path(a): a = [int(i) for i in a] color = "red" for i in a: if color == "red": if i == 1: color = "blue" elif i == 0: color = "red" elif color == "blue": if i == 1: color = "blue" elif i == 0: ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR STRING FOR VAR VAR IF VAR STRING IF VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER ASSIGN VAR STRING IF VAR STRING IF VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER ASSIGN VAR STRING IF VAR STRING IF VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER ASSIGN VAR STRING IF VAR STR...
There are $5$ cities in the country. The map of the country is given below. The tour starts from the red city. Each road is associated with a character. Initially, there is an empty string. Every time a road has been travelled the character associated gets appended to the string. At the green city either the string ca...
def next(c, n): if n == "1": return "B" elif c == "R": return "R" elif c == "B": return "Y" elif c == "Y": return "P" elif c == "P": return "G" else: return "R" for i in range(int(input())): string = input() c = "R" for i in range(len...
FUNC_DEF IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING RETURN STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIG...
There are $5$ cities in the country. The map of the country is given below. The tour starts from the red city. Each road is associated with a character. Initially, there is an empty string. Every time a road has been travelled the character associated gets appended to the string. At the green city either the string ca...
T = int(input()) l = [[0, 1], [2, 1], [3, 1], [4, 1], [0, 1]] for _ in range(T): s = input() a = 0 for i in s: x = int(i) a = l[a][x] if a == 4: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRI...
There are $5$ cities in the country. The map of the country is given below. The tour starts from the red city. Each road is associated with a character. Initially, there is an empty string. Every time a road has been travelled the character associated gets appended to the string. At the green city either the string ca...
st = dict() st["R"] = ["R", "B"] st["B"] = ["Y", "B"] st["Y"] = ["P", "B"] st["P"] = ["G", "B"] st["G"] = ["R", "B"] tn = int(input()) for _ in range(tn): si = input() cs = "R" for ch in si: cs = st[cs][int(ch)] if cs == "G": print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING LIST STRING STRING ASSIGN VAR STRING LIST STRING STRING ASSIGN VAR STRING LIST STRING STRING ASSIGN VAR STRING LIST STRING STRING ASSIGN VAR STRING LIST STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING FO...
There are $5$ cities in the country. The map of the country is given below. The tour starts from the red city. Each road is associated with a character. Initially, there is an empty string. Every time a road has been travelled the character associated gets appended to the string. At the green city either the string ca...
t = int(input()) for _ in range(t): s = input() if len(s) >= 4: x = s[-4] + s[-3] + s[-2] + s[-1] if x == "1000": print("YES") else: print("NO") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
There are $5$ cities in the country. The map of the country is given below. The tour starts from the red city. Each road is associated with a character. Initially, there is an empty string. Every time a road has been travelled the character associated gets appended to the string. At the green city either the string ca...
graph = [] for i in range(0, 5): l = [] for j in range(0, 2): l.append(0) graph.append(l) graph[0][0] = 0 graph[0][1] = 1 graph[1][0] = 2 graph[1][1] = 1 graph[2][0] = 3 graph[2][1] = 1 graph[3][0] = 4 graph[3][1] = 1 graph[4][0] = 0 graph[4][1] = 1 n = int(input()) while n: string = input() ...
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN ...
There are $5$ cities in the country. The map of the country is given below. The tour starts from the red city. Each road is associated with a character. Initially, there is an empty string. Every time a road has been travelled the character associated gets appended to the string. At the green city either the string ca...
for _ in range(int(input())): s = input() currnode = "red" for i in s: if currnode == "red": if i == "1": currnode = "blue" elif currnode == "blue": if i == "0": currnode = "yellow" elif currnode == "yellow": if i ==...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR VAR IF VAR STRING IF VAR STRING ASSIGN VAR STRING IF VAR STRING IF VAR STRING ASSIGN VAR STRING IF VAR STRING IF VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING IF VAR STRING IF VAR STRING ASSIGN VAR STRING ASSIGN VAR ST...
There are $5$ cities in the country. The map of the country is given below. The tour starts from the red city. Each road is associated with a character. Initially, there is an empty string. Every time a road has been travelled the character associated gets appended to the string. At the green city either the string ca...
n = int(input()) for i in range(n): s = input() j = len(s) - 1 if j > 2: if s[j - 3] == "1" and s[j - 2] == "0" and s[j - 1] == "0" and s[j] == "0": print("YES") else: print("NO") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL V...
There are $5$ cities in the country. The map of the country is given below. The tour starts from the red city. Each road is associated with a character. Initially, there is an empty string. Every time a road has been travelled the character associated gets appended to the string. At the green city either the string ca...
def makeAdj(): dic = {} dic[0, 0] = 0 dic[0, 1] = 1 dic[1, 0] = 2 dic[1, 1] = 1 dic[2, 1] = 1 dic[2, 0] = 3 dic[3, 0] = 4 dic[3, 1] = 1 dic[4, 1] = 1 dic[4, 0] = 0 return dic adj = makeAdj() t = int(input()) for i in range(t): s = str(input()) node = 0 for j...
FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN ...
There are $5$ cities in the country. The map of the country is given below. The tour starts from the red city. Each road is associated with a character. Initially, there is an empty string. Every time a road has been travelled the character associated gets appended to the string. At the green city either the string ca...
t = int(input()) for i in range(t): string = input() place = "R" for j in range(len(string)): if place == "R": if string[j] == "1": place = "B" elif place == "B": if string[j] == "0": place = "Y" elif place == "Y": i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR VAR STRING ASSIGN VAR STRING IF VAR STRING IF VAR VAR STRING ASSIGN VAR STRING IF VAR STRING IF VAR VAR STRING ASSIGN VAR STRING IF VAR VAR STRING ASSI...
There are $5$ cities in the country. The map of the country is given below. The tour starts from the red city. Each road is associated with a character. Initially, there is an empty string. Every time a road has been travelled the character associated gets appended to the string. At the green city either the string ca...
for _ in range(int(input())): a = input() d = { "q00": "q0", "q01": "q1", "q11": "q1", "q10": "q2", "q21": "q1", "q20": "q3", "q31": "q1", "q30": "q4", "q41": "q1", "q40": "q0", } g = "q0" for i in a: g += i ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 STRING FOR VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR...
There are $5$ cities in the country. The map of the country is given below. The tour starts from the red city. Each road is associated with a character. Initially, there is an empty string. Every time a road has been travelled the character associated gets appended to the string. At the green city either the string ca...
d = { "red": {"0": "red", "1": "blue"}, "blue": {"0": "yellow", "1": "blue"}, "yellow": {"0": "violet", "1": "blue"}, "violet": {"0": "green", "1": "blue"}, "green": {"0": "red", "1": "blue"}, } for _ in range(int(input())): s = input() c = "red" f = 0 for i in s: c = d[c][i]...
ASSIGN VAR DICT STRING STRING STRING STRING STRING DICT STRING STRING STRING STRING DICT STRING STRING STRING STRING DICT STRING STRING STRING STRING DICT STRING STRING STRING STRING DICT STRING STRING STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR ...
There are $5$ cities in the country. The map of the country is given below. The tour starts from the red city. Each road is associated with a character. Initially, there is an empty string. Every time a road has been travelled the character associated gets appended to the string. At the green city either the string ca...
for _ in range(int(input())): s = input() if len(s) < 4: print("NO") elif s[-4:] == "1000": print("YES") else: print("NO")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
There are $5$ cities in the country. The map of the country is given below. The tour starts from the red city. Each road is associated with a character. Initially, there is an empty string. Every time a road has been travelled the character associated gets appended to the string. At the green city either the string ca...
def main(): t = int(input()) for _ in range(t): sx = input() if sx[-4:] == "1000": print("YES") else: print("NO") main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
There are $5$ cities in the country. The map of the country is given below. The tour starts from the red city. Each road is associated with a character. Initially, there is an empty string. Every time a road has been travelled the character associated gets appended to the string. At the green city either the string ca...
t = int(input()) for i in range(t): s = input() l = len(s) if l >= 4: if s.endswith("1000"): print("YES") else: print("NO") else: print("NO")
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 IF VAR NUMBER IF FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
There are $5$ cities in the country. The map of the country is given below. The tour starts from the red city. Each road is associated with a character. Initially, there is an empty string. Every time a road has been travelled the character associated gets appended to the string. At the green city either the string ca...
def change_of_state(state, cur_no): if cur_no == 1: if state == "R": state = "B" elif state == "B": state = "B" elif state == "Y": state = "B" elif state == "P": state = "B" elif state == "G": state = "B" elif st...
FUNC_DEF IF VAR NUMBER IF VAR STRING ASSIGN VAR STRING IF VAR STRING ASSIGN VAR STRING IF VAR STRING ASSIGN VAR STRING IF VAR STRING ASSIGN VAR STRING IF VAR STRING ASSIGN VAR STRING IF VAR STRING ASSIGN VAR STRING IF VAR STRING ASSIGN VAR STRING IF VAR STRING ASSIGN VAR STRING IF VAR STRING ASSIGN VAR STRING IF VAR ST...
There are $5$ cities in the country. The map of the country is given below. The tour starts from the red city. Each road is associated with a character. Initially, there is an empty string. Every time a road has been travelled the character associated gets appended to the string. At the green city either the string ca...
t = int(input()) while t > 0: t = t - 1 s = input() a = [int(i) for i in s] if len(a) < 4: print("NO") continue sample = ["r0r", "r1b", "b1b", "b0y", "y1b", "y0p", "p0g", "p1b", "g1b", "g0b"] curr_state = "r" next_state = "" k = 0 z = 0 for i in a: z += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR STRING ASSIGN VAR STRI...
There are $5$ cities in the country. The map of the country is given below. The tour starts from the red city. Each road is associated with a character. Initially, there is an empty string. Every time a road has been travelled the character associated gets appended to the string. At the green city either the string ca...
path = { "R0": "R", "R1": "B", "B1": "B", "B0": "Y", "Y1": "B", "Y0": "P", "P1": "B", "P0": "G", "G1": "B", "G0": "R", } T = int(input()) for _ in range(T): s = input() current = "R" for c in s: current = path[current + c] print("YES" if current == "G" els...
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 FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL...
There are $5$ cities in the country. The map of the country is given below. The tour starts from the red city. Each road is associated with a character. Initially, there is an empty string. Every time a road has been travelled the character associated gets appended to the string. At the green city either the string ca...
T = int(input()) R = "R" G = "G" B = "B" Y = "Y" P = "P" Z = "0" O = "1" A = {} A[R] = {} A[R][Z] = R A[R][O] = B A[B] = {} A[B][Z] = Y A[B][O] = B A[Y] = {} A[Y][Z] = P A[Y][O] = B A[P] = {} A[P][Z] = G A[P][O] = B A[G] = {} A[G][Z] = R A[G][O] = B for t in range(T): s = input() c = R for i in s: c...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR DICT ASSIGN VAR VAR DICT ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR DICT ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN ...
There are $5$ cities in the country. The map of the country is given below. The tour starts from the red city. Each road is associated with a character. Initially, there is an empty string. Every time a road has been travelled the character associated gets appended to the string. At the green city either the string ca...
t = int(input()) i = 0 while i < t: s = input() y = s[-4:] if y == "1000": print("YES") else: print("NO") i = i + 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER
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): def dfs(v, path={}, sums=0): nonlocal ans, visited, Edge if v in visited or Edge[v] == -1: return if v in path: ans = max(ans, sums - path[v]) ...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER CLASS_DEF FUNC_DEF FUNC_DEF DICT NUMBER IF VAR VAR VAR VAR NUMBER RETURN IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR RETURN ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR...
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**7) class Solution: def largestSumCycle(self, N, Edge): def getsum(node): visited = [(False) for i in range(N)] s = node visited[node] = True temp = Edge[node] while visited[temp] != True: s ...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER NUMBER RETURN ASSIGN VAR VAR NUMBER ASSIGN VA...
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): vis = [-1] * N dp_arr = [0] * N res = -1 for i in range(N): if vis[i] == -1: temp, val, stack = i, 0, [] while True: vis[temp] = 0 dp_arr[temp] = v...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER LIST WHILE NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR 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): visited = [False] * N max_cycle_sum = -1 path = dict() path_keys = [] for u in range(N): if visited[u]: continue while -1 < u < N: if u in path: st...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR WHILE NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_C...
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, Edge, i, vis, pathV, ans): vis[i] = True pathV[i] = True if Edge[i] != -1: next = Edge[i] if not vis[next]: self.dfs(Edge, next, vis, pathV, ans) elif pathV[next]: ...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR N...
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): visited = [0] * N sc = -1 for i in range(N): sc = max(sc, self.nodes(Edge, visited, i)) return sc def nodes(self, Edge, visited, i): if visited[i] == 2: ...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR FUNC_DEF IF VAR VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE 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...
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...
import sys sys.setrecursionlimit(10**8) class Solution: def dfs(self, graph, s, cost, localV, globalV): if s in globalV: return -1 if s in localV: return cost - localV[s] localV[s] = cost res = -1 if graph[s] != -1: d = graph[s] ...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR RETURN BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN...
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): PointScore = [-1] * len(Edge) points = set([i for i in range(N)]) maxscore = [-1] def Walker(point, score): if point in points: points.remove(point) ...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL 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): OFFSET = 1 sums = [-1] * N result = -1 for i0 in range(N): if sums[i0] >= 0: continue sums[i0] = OFFSET csum = OFFSET + i0 i = Edge[i0] i1 = i0 ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER 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): visited = [-1] * N res = -1 for i in range(N): j = i mn = {} sm = 0 while visited[j] == -1: mn[j] = sm sm += j visited[j] = 1 j...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR RETURN 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(10**6) class Solution: def largestSumCycle(self, N, Edge): adjlist = [[] for i in range(N)] for i in range(len(Edge)): if Edge[i] != -1: adjlist[i].append(Edge[i]) visitedarr = [(False) for i in range(N)] ans = 0 ...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ...