description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Ivan is a student at Berland State University (BSU). There are n days in Berland week, and each of these days Ivan might have some classes at the university. There are m working hours during each Berland day, and each lesson at the university lasts exactly one hour. If at some day Ivan's first lesson is during i-th ho...
def min_sub_array(day, k): if not day: return [0] * (k + 1) n = len(day) best = [float("inf")] * (n + 1) best[0] = 0 best[1] = 1 for size in range(2, n + 1): for i in range(n + 1 - size): best[size] = min(best[size], day[i + size - 1] - day[i] + 1) output = [0] * ...
FUNC_DEF IF VAR RETURN BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_C...
Ivan is a student at Berland State University (BSU). There are n days in Berland week, and each of these days Ivan might have some classes at the university. There are m working hours during each Berland day, and each lesson at the university lasts exactly one hour. If at some day Ivan's first lesson is during i-th ho...
import sys n, m, k = map(int, input().split()) table = [input() for _ in range(n)] dp = [0] * (k + 1) for a in table: one = [] for i in range(m): if a[i] == "1": one.append(i) if not one: continue ni = len(one) subdp = [10**9] * (ni + 1) subdp[-1] = 0 for i in ra...
IMPORT ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST BIN...
Ivan is a student at Berland State University (BSU). There are n days in Berland week, and each of these days Ivan might have some classes at the university. There are m working hours during each Berland day, and each lesson at the university lasts exactly one hour. If at some day Ivan's first lesson is during i-th ho...
n, m, k = map(int, input().split()) DATA = [input() for i in range(n)] INF = 1 << 60 dp = [([INF] * (k + 10)) for i in range(n + 10)] dp[0][0] = 0 COST = [([INF] * (k + 10)) for i in range(n + 10)] for i, string in enumerate(DATA): stack = [] for j in range(m): if string[j] == "1": stack.app...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_...
Given a grid of size M*N with each cell consisting of an integer which represents points. We can move across a cell only if we have positive points. Whenever we pass through a cell, points in that cell are added to our overall points, the task is to find minimum initial points to reach cell (m-1, n-1) from (0, 0) by fo...
class Solution: def minPoints(self, points, M, N): N, M = len(points), len(points[0]) dp = [[(0) for _ in range(M)] for _ in range(N)] for i in range(N - 1, -1, -1): for j in range(M - 1, -1, -1): if i == N - 1 and j == M - 1: temp = points[i]...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR ASS...
Given a grid of size M*N with each cell consisting of an integer which represents points. We can move across a cell only if we have positive points. Whenever we pass through a cell, points in that cell are added to our overall points, the task is to find minimum initial points to reach cell (m-1, n-1) from (0, 0) by fo...
class Solution: def minPoints(self, points, M, N): k = max(M, N) dp = [([-1] * (k + 1)) for i in range(k + 1)] return self.helperFunction(points, M, N, 0, 0, dp) def helperFunction(self, points, M, N, x, y, dp): if x == M - 1 and y == N - 1: if points[x][y] <= 0: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER VAR FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR RETURN N...
Given a grid of size M*N with each cell consisting of an integer which represents points. We can move across a cell only if we have positive points. Whenever we pass through a cell, points in that cell are added to our overall points, the task is to find minimum initial points to reach cell (m-1, n-1) from (0, 0) by fo...
class Solution: def minPoints(self, points, n, m): inf = float("inf") dp = [[(0) for i in range(m)] for j in range(n)] for i in range(n - 1, -1, -1): for j in range(m - 1, -1, -1): if i == n - 1 and j == m - 1: if points[n - 1][m - 1] > 0: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER AS...
Given a grid of size M*N with each cell consisting of an integer which represents points. We can move across a cell only if we have positive points. Whenever we pass through a cell, points in that cell are added to our overall points, the task is to find minimum initial points to reach cell (m-1, n-1) from (0, 0) by fo...
class Solution: def minPoints(self, grid, n, m): t = [[(0) for i in range(m)] for j in range(n)] for i in range(n - 1, -1, -1): for j in range(m - 1, -1, -1): if i == n - 1 and j == m - 1: if grid[i][j] < 0: t[i][j] = abs(grid[...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER ASS...
Given a grid of size M*N with each cell consisting of an integer which represents points. We can move across a cell only if we have positive points. Whenever we pass through a cell, points in that cell are added to our overall points, the task is to find minimum initial points to reach cell (m-1, n-1) from (0, 0) by fo...
class Solution: def minPoints(self, points, n, m): dp = [[float("inf") for j in range(m + 1)] for i in range(n + 1)] dp[n][m - 1] = 1 dp[n - 1][m] = 1 for i in range(n - 1, -1, -1): for j in range(m - 1, -1, -1): minPoints = min(dp[i + 1][j], dp[i][j + 1]...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VA...
Given a grid of size M*N with each cell consisting of an integer which represents points. We can move across a cell only if we have positive points. Whenever we pass through a cell, points in that cell are added to our overall points, the task is to find minimum initial points to reach cell (m-1, n-1) from (0, 0) by fo...
def f(A, N, M, x, y, dp): if x >= N or y >= M: return 1000000000.0 if x == N - 1 and y == M - 1: if A[x][y] <= 0: return 1 + abs(A[x][y]) else: return 1 if dp[x][y] != -1: return dp[x][y] down = f(A, N, M, x + 1, y, dp) right = f(A, N, M, x, y ...
FUNC_DEF IF VAR VAR VAR VAR RETURN NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR BIN...
Given a grid of size M*N with each cell consisting of an integer which represents points. We can move across a cell only if we have positive points. Whenever we pass through a cell, points in that cell are added to our overall points, the task is to find minimum initial points to reach cell (m-1, n-1) from (0, 0) by fo...
import sys class Solution: def minPoints(self, points, M, N): return dp_mp2reach_destination(points) def _dp_mp2reach_destination(grid, rind, cind, r_length, c_length, dp_matrix): if rind >= r_length or cind >= c_length: return sys.maxsize if dp_matrix[rind][cind] != -1: return ...
IMPORT CLASS_DEF FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR VAR VAR RETURN VAR IF VAR VAR VAR NUMBER RETURN VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN VAR VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR ...
Given a grid of size M*N with each cell consisting of an integer which represents points. We can move across a cell only if we have positive points. Whenever we pass through a cell, points in that cell are added to our overall points, the task is to find minimum initial points to reach cell (m-1, n-1) from (0, 0) by fo...
class Solution: def minPoints(self, points, M, N): result = [[(0) for i in range(N)] for j in range(M)] if points[M - 1][N - 1] > 0: result[M - 1][N - 1] = 1 else: result[M - 1][N - 1] = abs(points[M - 1][N - 1]) + 1 for i in range(M - 2, -1, -1): ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VA...
Given a grid of size M*N with each cell consisting of an integer which represents points. We can move across a cell only if we have positive points. Whenever we pass through a cell, points in that cell are added to our overall points, the task is to find minimum initial points to reach cell (m-1, n-1) from (0, 0) by fo...
class Solution: def minPoints(self, l, n, m): n = len(l) m = len(l[0]) dp = [[(0) for _ in range(m)] for _ in range(n)] dp[-1][-1] = min(0, l[-1][-1]) for i in range(n - 2, -1, -1): dp[i][-1] = min(0, dp[i + 1][-1] + l[i][-1]) for i in range(m - 2, -1, -1...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR BI...
Given a grid of size M*N with each cell consisting of an integer which represents points. We can move across a cell only if we have positive points. Whenever we pass through a cell, points in that cell are added to our overall points, the task is to find minimum initial points to reach cell (m-1, n-1) from (0, 0) by fo...
class Solution: def minPoints(self, points, M, N): r, c, grid = M, N, points dp = [[(0) for i in range(c)] for j in range(r)] if grid[r - 1][c - 1] < 0: dp[r - 1][c - 1] = 1 - grid[r - 1][c - 1] else: dp[r - 1][c - 1] = 1 for i in range(c - 2, -1, -1)...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR...
Given a grid of size M*N with each cell consisting of an integer which represents points. We can move across a cell only if we have positive points. Whenever we pass through a cell, points in that cell are added to our overall points, the task is to find minimum initial points to reach cell (m-1, n-1) from (0, 0) by fo...
class Solution: def minPoints(self, points, M, N): for i in range(M - 1, -1, -1): for j in range(N - 1, -1, -1): if i == M - 1 and j == N - 1: if points[i][j] > 0: points[i][j] = 0 elif i == M - 1: x...
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VA...
Given a grid of size M*N with each cell consisting of an integer which represents points. We can move across a cell only if we have positive points. Whenever we pass through a cell, points in that cell are added to our overall points, the task is to find minimum initial points to reach cell (m-1, n-1) from (0, 0) by fo...
class Solution: def minPoints(self, points, m, n): points[m - 1][n - 1] = min(points[m - 1][n - 1], 0) for i in range(m - 2, -1, -1): points[i][n - 1] = min(points[i][n - 1] + points[i + 1][n - 1], 0) for i in range(n - 2, -1, -1): points[m - 1][i] = min(points[m - 1...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC...
Given a grid of size M*N with each cell consisting of an integer which represents points. We can move across a cell only if we have positive points. Whenever we pass through a cell, points in that cell are added to our overall points, the task is to find minimum initial points to reach cell (m-1, n-1) from (0, 0) by fo...
import sys sys.setrecursionlimit(10**6) class Solution: def minPoints(self, points, N, M): dp = [[(-1) for i in range(M + 1)] for j in range(N + 1)] def recursive(points, dp, N, M, i=0, j=0): if i >= N or j >= M: return float("inf") if i == N - 1 and j ==...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF NUMBER NUMBER IF VAR VAR VAR VAR RETURN FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER RETURN FUNC_CALL VAR BIN_...
Given a grid of size M*N with each cell consisting of an integer which represents points. We can move across a cell only if we have positive points. Whenever we pass through a cell, points in that cell are added to our overall points, the task is to find minimum initial points to reach cell (m-1, n-1) from (0, 0) by fo...
import sys class Solution: def minPoints(self, points, M, N): t = [[(-1) for i in range(N + 1)] for j in range(M + 1)] y = self.fn(0, 0, M, N, points, t) return y def fn(self, i, j, m, n, grid, t): if i >= m or j >= n: return sys.maxsize if i == m - 1 and ...
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR VAR RETURN VAR FUNC_DEF IF VAR VAR VAR VAR RETURN VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VA...
Given a grid of size M*N with each cell consisting of an integer which represents points. We can move across a cell only if we have positive points. Whenever we pass through a cell, points in that cell are added to our overall points, the task is to find minimum initial points to reach cell (m-1, n-1) from (0, 0) by fo...
class Solution: def minPoints(self, points, M, N): dp = [([10**9] * (N + 1)) for i in range(M + 1)] dp[M - 1][N] = 1 dp[M][N - 1] = 1 for i in range(M - 1, -1, -1): for j in range(N - 1, -1, -1): dp[i][j] = max(min(dp[i + 1][j], dp[i][j + 1]) - points[i][...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST BIN_OP NUMBER NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR ...
Given a grid of size M*N with each cell consisting of an integer which represents points. We can move across a cell only if we have positive points. Whenever we pass through a cell, points in that cell are added to our overall points, the task is to find minimum initial points to reach cell (m-1, n-1) from (0, 0) by fo...
class Solution: def minPoints(self, points, M, N): m, n = M, N dp = [[(-1) for i in range(n)] for j in range(m)] dp[m - 1][n - 1] = 1 if points[m - 1][n - 1] >= 0 else 1 - points[m - 1][n - 1] for j in range(n - 2, -1, -1): if points[m - 1][j] >= 0: dp[m ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR ...
Given a grid of size M*N with each cell consisting of an integer which represents points. We can move across a cell only if we have positive points. Whenever we pass through a cell, points in that cell are added to our overall points, the task is to find minimum initial points to reach cell (m-1, n-1) from (0, 0) by fo...
class Solution: def minPoints(self, points, m, n): dp = [] for i in range(m): temp = [] for j in range(n): temp.append(0) dp.append(temp) if points[m - 1][n - 1] < 1: dp[m - 1][n - 1] = 1 - points[m - 1][n - 1] else: ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP...
Given a grid of size M*N with each cell consisting of an integer which represents points. We can move across a cell only if we have positive points. Whenever we pass through a cell, points in that cell are added to our overall points, the task is to find minimum initial points to reach cell (m-1, n-1) from (0, 0) by fo...
class Solution: def minPoints(self, points, M, N): mat = [[(0) for i in range(N)] for j in range(M)] if points[-1][-1] >= 0: mat[-1][-1] = 1 else: mat[-1][-1] = abs(points[-1][-1]) + 1 for i in range(M - 2, -1, -1): x = mat[i + 1][N - 1] - points[...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUM...
Given a grid of size M*N with each cell consisting of an integer which represents points. We can move across a cell only if we have positive points. Whenever we pass through a cell, points in that cell are added to our overall points, the task is to find minimum initial points to reach cell (m-1, n-1) from (0, 0) by fo...
import sys class Solution: def minPoints(self, points, M, N): dp = [([-1] * N) for _ in range(M)] def solve(i, j): if i == M - 1 and j == N - 1: return -1 * points[i][j] + 1 if points[i][j] <= 0 else 1 if i > M - 1 or j > N - 1: return sys....
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN VAR VAR VAR NUMBER BIN_OP BIN_OP NUMBER VAR VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN VAR IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR...
Given a grid of size M*N with each cell consisting of an integer which represents points. We can move across a cell only if we have positive points. Whenever we pass through a cell, points in that cell are added to our overall points, the task is to find minimum initial points to reach cell (m-1, n-1) from (0, 0) by fo...
class Solution: def minPoints(self, arr, M, N): dp = [[(78263476) for j in range(len(arr[0]))] for i in range(len(arr))] for i in range(len(arr) - 1, -1, -1): for j in range(len(arr[0]) - 1, -1, -1): if i == len(arr) - 1 and j == len(arr[0]) - 1: dp[i...
CLASS_DEF FUNC_DEF 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 BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL V...
Given a grid of size M*N with each cell consisting of an integer which represents points. We can move across a cell only if we have positive points. Whenever we pass through a cell, points in that cell are added to our overall points, the task is to find minimum initial points to reach cell (m-1, n-1) from (0, 0) by fo...
import sys class Solution: def minPoints(self, dungeon, m, n): memo = [[(-1) for _ in range(n)] for i in range(m)] return self.recursion(dungeon, 0, 0, memo) def recursion(self, grid, i, j, memo): m = len(grid) n = len(grid[0]) if i == m - 1 and j == n - 1: ...
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR NUMBER NUMBER VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN VAR VAR VAR NUMBER NUMBER BIN_OP VAR VAR VAR NUMBER IF VAR VA...
Given a grid of size M*N with each cell consisting of an integer which represents points. We can move across a cell only if we have positive points. Whenever we pass through a cell, points in that cell are added to our overall points, the task is to find minimum initial points to reach cell (m-1, n-1) from (0, 0) by fo...
class Solution: def minPoints(self, points, M, N): d = [[(0) for i in range(N)] for j in range(M)] d[M - 1][N - 1] = 0 if points[M - 1][N - 1] < 0: d[M - 1][N - 1] = points[M - 1][N - 1] for i in range(M - 1, -1, -1): for j in range(N - 1, -1, -1): ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER N...
Given a grid of size M*N with each cell consisting of an integer which represents points. We can move across a cell only if we have positive points. Whenever we pass through a cell, points in that cell are added to our overall points, the task is to find minimum initial points to reach cell (m-1, n-1) from (0, 0) by fo...
class Solution: def minPoints(self, points, M, N): dp = [([float("inf")] * (N + 1)) for i in range(M + 1)] dp[M][N - 1] = 1 dp[M - 1][N] = 1 for i in reversed(range(M)): for j in reversed(range(N)): dp[i][j] = max(min(dp[i + 1][j], dp[i][j + 1]) - points[...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP FUN...
Given a grid of size M*N with each cell consisting of an integer which represents points. We can move across a cell only if we have positive points. Whenever we pass through a cell, points in that cell are added to our overall points, the task is to find minimum initial points to reach cell (m-1, n-1) from (0, 0) by fo...
class Solution: def minPoints(self, points, m, n): dp = [] for i in range(m + 1): dp.append([10**9] * (n + 1)) dp[m - 1][n] = 1 dp[m][n - 1] = 1 for i in range(m - 1, -1, -1): for j in range(n - 1, -1, -1): x = min(dp[i + 1][j], dp[i][...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST BIN_OP NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER N...
Given a grid of size M*N with each cell consisting of an integer which represents points. We can move across a cell only if we have positive points. Whenever we pass through a cell, points in that cell are added to our overall points, the task is to find minimum initial points to reach cell (m-1, n-1) from (0, 0) by fo...
class Solution: def minPoints(self, points, M, N): min_st_cost = [([float("inf")] * N) for i in range(M)] min_st_cost[M - 1][N - 1] = ( abs(points[M - 1][N - 1]) if points[M - 1][N - 1] < 0 else 0 ) for i in range(M - 1, -1, -1): for j in range(N - 1, -1, -1)...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR ...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def minOperations(self, s1, s2): a = len(s1) b = len(s2) dp = [([0] * (b + 1)) for i in range(a + 1)] for i in range(1, b + 1): dp[0][i] = i for i in range(1, a + 1): dp[i][0] = i for i in range(1, a + 1): charA = s...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR FOR VAR FUNC_...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def minOperations(self, s1, s2): n = len(s1) m = len(s2) prev = [(0) for _ in range(m + 1)] curr = [(0) for _ in range(m + 1)] for row in range(1, n + 1): for col in range(1, m + 1): if s1[row - 1] == s2[col - 1]: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR N...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def minOperations(self, s1, s2): m = len(s1) n = len(s2) memo = [[(-1) for _ in range(n + 1)] for _ in range(m + 1)] for i in range(m + 1): for j in range(n + 1): if i == 0 or j == 0: memo[i][j] = 0 elif...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMB...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def minOperations(self, s1, s2): l1 = len(s1) l2 = len(s2) dp = [[(0) for x in range(l2 + 1)] for x in range(l1 + 1)] for i in range(l1 + 1): for j in range(l2 + 1): if i * j == 0: dp[i][j] = 0 for i in range(1,...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR ...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def ls(self, x, y, s1, s2, dp): if x == 0 or y == 0: return 0 if dp[x][y] != -1: return dp[x][y] if s1[x - 1] == s2[y - 1]: dp[x][y] = 1 + self.ls(x - 1, y - 1, s1, s2, dp) return dp[x][y] else: dp[x][y] = m...
CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NU...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def minOperations(self, s1, s2): x = len(s1) y = len(s2) subset = [([-1] * (y + 1)) for i in range(x + 1)] for i in range(x + 1): subset[i][0] = 0 for j in range(y + 1): subset[0][j] = 0 for i in range(1, x + 1): fo...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def f(self, s, t, x, y): prev = [0] * (y + 1) for ind1 in range(1, x + 1): curr = [0] * (y + 1) for ind2 in range(1, y + 1): if s[ind1 - 1] == t[ind2 - 1]: curr[ind2] = 1 + prev[ind2 - 1] else: ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VA...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def minOperations(self, s1, s2): l1 = len(s1) l2 = len(s2) dp = [[(0) for i in range(l2 + 1)] for j in range(l1 + 1)] for i in range(1, l1 + 1): for j in range(1, l2 + 1): if s1[i - 1] == s2[j - 1]: dp[i][j] = 1 + dp[i ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR V...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
import itertools class Solution: def minOperations(self, s1, s2): m = len(s1) n = len(s2) dp = [([0] * (n + 1)) for _ in range(m + 1)] for i, j in itertools.product(range(1, m + 1), range(1, n + 1)): dp[i][j] = ( 1 + dp[i - 1][j - 1] if ...
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def minOperations(self, s1, s2): dp = [[(0) for i in range(len(s2) + 1)] for _ in range(len(s1) + 1)] for i in range(len(s1) + 1): for j in range(len(s2) + 1): if i == len(s1) and j != len(s2): dp[i][j] = len(s2) - j el...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FU...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def minOperations(self, s1, s2): r = len(s1) c = len(s2) dp = [[(0) for i in range(c + 1)] for j in range(r + 1)] for i in range(1, r + 1): for j in range(1, c + 1): if s1[i - 1] == s2[j - 1]: dp[i][j] = 1 + dp[i - 1][j...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR V...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def minOperations(self, s1, s2): def find(s1, s2, i, j, dp): if i == len(s1) and j == len(s2): return 0 if i == len(s1) and j != len(s2): return len(s2) - j if i != len(s1) and j == len(s2): return len(s1) ...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def find_lcs(self, dp, txt1, txt2, m, n): if m == 0 or n == 0: return 0 if dp[m][n] != -1: return dp[m][n] if txt1[m - 1] == txt2[n - 1]: dp[m][n] = 1 + self.find_lcs(dp, txt1, txt2, m - 1, n - 1) return dp[m][n] else: ...
CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR B...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def helper(self, i, j, s1, s2, dp): if i < 0 or j < 0: return 0 if dp[i][j] != -1: return dp[i][j] if s1[i] == s2[j]: return 1 + self.helper(i - 1, j - 1, s1, s2, dp) else: dp[i][j] = max( self.helper(i ...
CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR IF VAR VAR VAR VAR RETURN BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VA...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
def maxLength(dp): ans = 0 for i in range(len(dp)): for j in range(len(dp[0])): ans = max(ans, dp[i][j]) return ans def helper(s1, s2, dp, x, y): if x == 0 or y == 0: return 0 if dp[x][y] != -1: return dp[x][y] if s1[x - 1] == s2[y - 1]: dp[x][y] = 1...
FUNC_DEF 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 VAR VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def minOperations(self, s1, s2): x = len(s1) y = len(s2) dp = [[(-1) for i in range(y)] for j in range(x)] def answer(i, j, s1, s2): if i == -1 or j == -1: return 0 if dp[i][j] != -1: return dp[i][j] ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP V...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def subs(self, s1, s2): n = len(s1) m = len(s2) prev = [0] * (m + 1) curr = [0] * (m + 1) for i in range(1, n + 1): for j in range(1, m + 1): if s1[i - 1] == s2[j - 1]: curr[j] = 1 + prev[j - 1] ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def minOperations(self, s1, s2): lcs = LCSDP(s1, s2, len(s1), len(s2)) numOfDel = len(s1) - lcs numOfIns = len(s2) - lcs return numOfDel + numOfIns def LCSDP(X, Y, n, m): dp = [[(-1) for i in range(m + 1)] for j in range(n + 1)] for i in range(n + 1): ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR RETURN BIN_OP VAR VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VA...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def minOperations(self, s1, s2): st1 = s1 st2 = s2 m = len(st1) n = len(st2) dp = [[(0) for i in range(n + 1)] for j in range(m + 1)] for i in range(1, m + 1): for j in range(1, n + 1): if st1[i - 1] == st2[j - 1]: ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR ...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def minOperations(self, s1, s2): dp = [[(-1) for j in range(len(s2) + 1)] for i in range(len(s1) + 1)] for i in range(len(s1) + 1): dp[i][0] = 0 for i in range(len(s2) + 1): dp[0][i] = 0 for ind1 in range(1, len(s1) + 1): for ind2 ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def minOperations(self, s1, s2): def computeLCS(str1, str2): m, n = len(str1), len(str2) dp = [[(-1) for j in range(n + 1)] for i in range(m + 1)] for j in range(n + 1): dp[0][j] = 0 for i in range(1, m + 1): d...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VA...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def func(self, X, Y, m, n, t): for i in range(m + 1): for j in range(n + 1): if i == 0 or j == 0: t[i][j] = 0 for i in range(1, m + 1): for j in range(1, n + 1): if X[i - 1] == Y[j - 1]: ...
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUM...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def minOperations(self, s1, s2): m = len(s1) n = len(s2) dp = [([0] * (n + 1)) for _ in range(m + 1)] for i in range(m + 1): for j in range(n + 1): x = i y = j if x == 0 or y == 0: dp[i][...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBE...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def lcs(self, s1: str, s2: str) -> int: dp = [([0] * (len(s2) + 1)) for j in range(len(s1) + 1)] for i in range(1, len(s1) + 1): for j in range(1, len(s2) + 1): if s1[i - 1] == s2[j - 1]: dp[i][j] = 1 + dp[i - 1][j - 1] ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR V...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def minOperations(self, s1, s2): m = len(s1) n = len(s2) X = s1 Y = s2 dp = [([-1] * (n + 1)) for i in range(m + 1)] def lcs(x, y, n, m): if n == 0 or m == 0: return 0 if dp[n][m] != -1: return ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR ...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def minOperations(self, string1, string2): cache = {} def LCS(indx1, indx2): if indx1 >= len(string1) or indx2 >= len(string2): return abs(len(string1) - indx1) + abs(len(string2) - indx2) if (indx1, indx2) in cache: return ca...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR IF VAR VAR VAR RETURN VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN ...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def minOperations(self, s1, s2): lcs = tabulation(s1, s2, len(s1), len(s2)) return len(s1) + len(s2) - 2 * lcs def tabulation(s1, s2, n, m) -> int: t = [([0] * (m + 1)) for i in range(n + 1)] ans = 0 for i in range(1, n + 1): for j in range(1, m + 1): ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def lcs(self, s1, s2, x, y): t = [[(-1) for _ in range(y + 1)] for _ in range(x + 1)] for i in range(x + 1): for j in range(y + 1): if i == 0 or j == 0: t[i][j] = 0 for i in range(1, x + 1): for j in range(1, y + 1)...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def f(self, s1, s2, ind1, ind2, dp): if ind1 < 0 or ind2 < 0: return 0 if dp[ind1][ind2] != -1: return dp[ind1][ind2] if s1[ind1] == s2[ind2]: dp[ind1][ind2] = 1 + self.f(s1, s2, ind1 - 1, ind2 - 1, dp) return dp[ind1][ind2] ...
CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR RETURN VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMB...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def minOperations(self, s1, s2): m = len(s1) n = len(s2) prev = [(0) for j in range(n + 1)] curr = [(0) for j in range(n + 1)] for index1 in range(1, m + 1): for index2 in range(1, n + 1): if s1[index1 - 1] == s2[index2 - 1]: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR N...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def minOperations(self, s1, s2): n = len(s1) m = len(s2) c = self.fun(m, n) return n - c + m - c def fun(self, n, m): dp = [[(0) for _ in range(n + 1)] for _ in range(m + 1)] for i in range(m + 1): for j in range(n + 1): ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_O...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def minOperations(self, s1, s2): dp = [[(0) for j in range(len(s2) + 1)] for i in range(len(s1) + 1)] for i in range(1, len(s1) + 1): for j in range(1, len(s2) + 1): if s1[i - 1] == s2[j - 1]: answer = 1 + dp[i - 1][j - 1] ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def minOperations(self, s1, s2): delete = 0 insert = 0 n = len(s1) m = len(s2) res = self.f(s1, s2, n, m) delete = n - res insert = m - res return delete + insert def f(self, s1, s2, n, m): dp = [[(0) for i in range(m + 1)...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN BIN_OP VAR VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR ...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def minOperations(self, s1, s2): dp = dict() def go(i, j): if i < 0 and j < 0: return 0 if i < 0: return j + 1 if j < 0: return i + 1 if (i, j) in dp: return dp[i, j] ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN BIN_OP VAR NUMBER IF VAR NUMBER RETURN BIN_OP VAR NUMBER IF VAR VAR VAR RETURN VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL V...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: dp = [] def gen(self, s1, s2, r1, r2): if r1 < 0 or r2 < 0: return abs(r1 - r2) l = 99999 if self.dp[r1][r2] != -1: return self.dp[r1][r2] if s1[r1] == s2[r2]: l = self.gen(s1, s2, r1 - 1, r2 - 1) m = self.gen(s1, s2, r...
CLASS_DEF ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN V...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def minOperations(self, s1, s2): def lcs(x, y, s1, s2): T = [([0] * (y + 1)) for i in range(x + 1)] for i in range(1, x + 1): for j in range(1, y + 1): if s1[i - 1] == s2[j - 1]: T[i][j] = 1 + T[i - 1][j - ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR N...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def minOperations(self, s1, s2): dp = [([float("inf")] * (len(s2) + 1)) for i in range(len(s1) + 1)] for i in range(len(s1)): dp[i][-1] = i + 1 for j in range(len(s2)): dp[-1][j] = j + 1 dp[-1][-1] = 0 for i in range(len(s1)): ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMB...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def minOperations(self, s1, s2): dp = [[(-1) for a in range(len(s2))] for b in range(len(s1))] def solve(i, j): if i < 0 or j < 0: return 0 if dp[i][j] != -1: return dp[i][j] if s1[i] == s2[j]: dp[i...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR F...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def minOperations(self, str1, str2): m, n = len(str1), len(str2) dp = [[(0) for x in range(n + 1)] for x in range(m + 1)] for i in range(m + 1): for j in range(n + 1): if i == 0: dp[i][j] = j elif j == 0: ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR...
Given two strings str1 and str2. The task is to remove or insert the minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point. Example 1: Input: str1 = "heap", str2 = "pea...
class Solution: def SpaceOptimized(self, ind1, ind2, str1, str2): prev = [0] * (ind2 + 1) dp = [0] * (ind2 + 1) for row in range(1, ind1 + 1): for col in range(1, ind2 + 1): if str1[row - 1] == str2[col - 1]: dp[col] = 1 + prev[col - 1] ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VA...
Akshara is a Maths teacher at Dynamic Public School.One day she decided to take an unusual test of all her students.She took all her students to a fair.There she took them to a candy room.The room had 2 doors and behind each door was unlimited supply of candies.The excitement of the students could not be measured.Each ...
from sys import stdin def getInt(): return list(map(int, stdin.readline().split())) def solve(): n, x = getInt() A = getInt() A.sort() s = sum(A) W = [False] * (s + 1) W[0] = True for e in A: for w in range(s, e - 1, -1): W[w] = W[w] or W[w - e] ret = 10000000...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER A...
Automatons, or Finite State Machines (FSM), are extremely useful to programmers when it comes to software design. You will be given a simplistic version of an FSM to code for a basic TCP session. The outcome of this exercise will be to return the correct state of the TCP FSM based on the array of events given. ------...
STATES = { "CLOSED": {"APP_PASSIVE_OPEN": "LISTEN", "APP_ACTIVE_OPEN": "SYN_SENT"}, "LISTEN": {"RCV_SYN": "SYN_RCVD", "APP_SEND": "SYN_SENT", "APP_CLOSE": "CLOSED"}, "SYN_RCVD": {"APP_CLOSE": "FIN_WAIT_1", "RCV_ACK": "ESTABLISHED"}, "SYN_SENT": { "RCV_SYN": "SYN_RCVD", "RCV_SYN_ACK": "ES...
ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING DICT STRING STRING STRING STRING DICT STRING STRING STRING STRING STRING STRING DICT STRING STRING STRING STRING DICT STRING STRING STRING STRING STRING STRING DICT STRING STRING STRING STRING DICT STRING STRING STRING STRING S...
Automatons, or Finite State Machines (FSM), are extremely useful to programmers when it comes to software design. You will be given a simplistic version of an FSM to code for a basic TCP session. The outcome of this exercise will be to return the correct state of the TCP FSM based on the array of events given. ------...
NEW_STATE = { "CLOSED__APP_PASSIVE_OPEN": "LISTEN", "CLOSED__APP_ACTIVE_OPEN": "SYN_SENT", "LISTEN__RCV_SYN": "SYN_RCVD", "LISTEN__APP_SEND": "SYN_SENT", "LISTEN__APP_CLOSE": "CLOSED", "SYN_RCVD__APP_CLOSE": "FIN_WAIT_1", "SYN_RCVD__RCV_ACK": "ESTABLISHED", "SYN_SENT__RCV_SYN": "SYN_RCVD...
ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING FUNC_DEF STRING FOR VAR ...
Automatons, or Finite State Machines (FSM), are extremely useful to programmers when it comes to software design. You will be given a simplistic version of an FSM to code for a basic TCP session. The outcome of this exercise will be to return the correct state of the TCP FSM based on the array of events given. ------...
def traverse_TCP_states(events): lib = { ("CLOSED", "APP_PASSIVE_OPEN"): "LISTEN", ("CLOSED", "APP_ACTIVE_OPEN"): "SYN_SENT", ("LISTEN", "RCV_SYN"): "SYN_RCVD", ("LISTEN", "APP_SEND"): "SYN_SENT", ("LISTEN", "APP_CLOSE"): "CLOSED", ("SYN_RCVD", "APP_CLOSE"): "FIN_WAIT...
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 STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING S...
You are given a text consisting of $n$ space-separated words. There is exactly one space character between any pair of adjacent words. There are no spaces before the first word and no spaces after the last word. The length of text is the number of letters and spaces in it. $w_i$ is the $i$-th word of text. All words co...
from sys import stdin def kmp(pat, txt): leng = 0 i = 1 ans = 0 M = len(pat) N = len(txt) lps = [0] * M j = 0 while i < M: if pat[i] == pat[leng]: leng += 1 lps[i] = leng i += 1 elif leng != 0: leng = lps[leng - 1] ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR ...
You are given a text consisting of $n$ space-separated words. There is exactly one space character between any pair of adjacent words. There are no spaces before the first word and no spaces after the last word. The length of text is the number of letters and spaces in it. $w_i$ is the $i$-th word of text. All words co...
N = 303 eq = [] dp = [] for i in range(N): eq.append([False] * N) for i in range(N): dp.append([0] * N) n = int(input()) s = input() allsum = len(s) s = s.split() for i in range(n): eq[i][i] = True for j in range(i): eq[i][j] = eq[j][i] = s[i] == s[j] for i in range(n - 1, -1, -1): for j in ...
ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CAL...
You are given a text consisting of $n$ space-separated words. There is exactly one space character between any pair of adjacent words. There are no spaces before the first word and no spaces after the last word. The length of text is the number of letters and spaces in it. $w_i$ is the $i$-th word of text. All words co...
import sys input = sys.stdin.readline n = int(input()) s = input() a = list(s.split()) eq = [[(0) for i in range(n)] for j in range(n)] dp = [[(0) for i in range(n)] for j in range(n)] for i in range(n): eq[i][i] = 1 for j in range(0, i): if a[i] == a[j]: eq[i][j] += 1 eq[j][i] ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL V...
You are given a text consisting of $n$ space-separated words. There is exactly one space character between any pair of adjacent words. There are no spaces before the first word and no spaces after the last word. The length of text is the number of letters and spaces in it. $w_i$ is the $i$-th word of text. All words co...
n = int(input()) arr = input() final = len(arr) arr = arr.split() lens = [(0) for x in range(n)] visit = [(0) for x in range(n)] cnt = 0 ans = 0 for i in range(n): if visit[i]: continue lens[cnt] = len(arr[i]) for j in range(i + 1, n): if arr[j] == arr[i]: arr[j] = cnt ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC...
Read problems statements in Mandarin Chinese and Russian as well. You are given a function f which is defined as : Your task is to find the value of where M is given in input. ------ Input Format ------ First line contains T, the number of test cases. First line of each test case contain 3 space separated int...
t = int(input()) for each_t in range(t): n, m, q = input().split() n, m, q = int(n), int(m), int(q) a = [0] * (n + 1) if n % 2 == 0: mid = n // 2 a[mid] = mid + 1 b = mid c = mid + 2 else: mid = n // 2 + 1 a[mid] = 1 b = mid c = mid + 1...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER A...
Read problems statements in Mandarin Chinese and Russian as well. You are given a function f which is defined as : Your task is to find the value of where M is given in input. ------ Input Format ------ First line contains T, the number of test cases. First line of each test case contain 3 space separated int...
for _ in range(int(input())): n, mod, q = map(int, input().split()) ls = [0] * n ls[1] = n for i in range(2, n): ls[1] = ls[1] * i % mod n += 1 if n % 2: num, den, cur = n // 2 + 1, n // 2, n // 2 + 1 else: num, den, cur = n // 2, n // 2, 1 n -= 1 ls[den] = cu...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR ...
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful. Therefore, Sasha decided ...
n = int(input()) b = {(0, 0): 1} ans, i, x = 0, 0, 0 for a in map(int, input().split()): x ^= a i += 1 t = b.get((x, i % 2), 0) ans += t b[x, i % 2] = t + 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful. Therefore, Sasha decided ...
n = int(input()) a = [int(x) for x in input().split()] d0 = {} d1 = {} c = 0 count = 0 for i in range(n): c = c ^ a[i] if c == 0 and i % 2 == 1: count = count + 1 if i % 2 == 0: l = d0.get(c, 0) count = count + l if l == 0: d0[c] = 0 d0[c] = d0[c] + 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSI...
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful. Therefore, Sasha decided ...
n = int(input()) s = list(map(int, input().rstrip().split())) resp = [s[0]] resd = [0, s[0] ^ s[1]] for i in range(2, n): if i % 2 == 0: resp += [resd[-1] ^ s[i]] else: resd += [resp[-1] ^ s[i]] def f(lis): dic = {} s = 0 for el in lis: try: dic[el] += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST NUMBER BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER VAR LIST BIN_OP VAR NUMBER VAR VAR VAR LIST BIN_OP VAR NUMBER VA...
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful. Therefore, Sasha decided ...
def main(): n = int(input()) a = list(map(int, input().split())) cnt = [([0] * (1 << 21)) for _ in range(2)] cnt[1][0] = 1 curr, ret = 0, 0 for i, x in enumerate(a): curr ^= x ret += cnt[i % 2][curr] cnt[i % 2][curr] += 1 print(ret) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ...
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful. Therefore, Sasha decided ...
n = int(input()) a = [int(x) for x in input().split()] pref = [0] count = [[0, 0] for x in range(2**20 + 10)] for i in range(0, n): pref.append(pref[i] ^ a[i]) index = 0 ans = 0 for p in pref: ans += count[p][index % 2] count[p][index % 2] += 1 index += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR...
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful. Therefore, Sasha decided ...
n = int(input()) A = list(map(int, input().split())) even = {} odd = {} cnt = 0 B = [A[0]] for i in range(1, n): B.append(B[-1] ^ A[i]) for u in B: even[u] = 0 odd[u] = 0 for x in range(n): if x % 2 == 0: even[B[x]] += 1 else: odd[B[x]] += 1 for t in even: cnt += even[t] * (even[...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR...
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful. Therefore, Sasha decided ...
def get(): return list(map(int, input().split())) n = int(input()) a = get() xor = (n + 1) * [0] for i in range(1, n + 1): xor[i] = xor[i - 1] ^ a[i - 1] ans = 0 b = [{}, {}] for i in range(2): for j in range(i, n + 1, 2): if not xor[j] in b[i]: b[i][xor[j]] = 0 ans += b[i][xor...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIG...
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful. Therefore, Sasha decided ...
n = int(input()) a = list(map(int, input().split())) x, cnt = 0, 0 s = [[0] * 2**20 + 3 * [0], [0] * 2**20 + 3 * [0]] s[1][0] = 1 for i in range(n): x ^= a[i] cnt += s[i % 2][x] s[i % 2][x] += 1 print(cnt)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST BIN_OP BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER BIN_OP NUMBER LIST NUMBER BIN_OP BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER BIN_OP NUMBER LIST NUMBER ASSIGN VAR NUMBER NUMBE...
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful. Therefore, Sasha decided ...
n = int(input()) a = list(map(int, input().split())) cnt = [[(0) for i in range(int(2 << 20) + 10)], [(0) for i in range(int(2 << 20) + 10)]] cnt[1][0] = 1 x = 0 ans = 0 for i in range(n): x ^= a[i] ans += cnt[i % 2][x] cnt[i % 2][x] += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP NUMBER NUMBER NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ...
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful. Therefore, Sasha decided ...
import sys input = sys.stdin.readline n = int(input()) A = list(map(int, input().split())) AX = [0, A[0]] for i in range(1, n): AX.append(AX[i] ^ A[i]) LIST = sorted(set(AX)) DICT = dict() for i in range(len(LIST)): DICT[LIST[i]] = i NUMLIST = [[] for i in range(len(LIST))] for i in range(n + 1): NUMLIST[D...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CA...
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful. Therefore, Sasha decided ...
list_int_input = lambda inp: list(map(int, inp.split())) int_input = lambda inp: int(inp) string_to_list_input = lambda inp: list(inp) n = int(input()) a = list_int_input(input()) a = [0] + a xl = [] for ind, val in enumerate(a): if ind > 0: val = xl[-1] ^ val xl.append(val) el = xl[::2] ol = xl[1::2] d...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ...
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful. Therefore, Sasha decided ...
n = int(input()) lst = list(map(int, input().split())) total = 0 for i in range(1, n): lst[i] = lst[i] ^ lst[i - 1] def ikili(n): return n * (n - 1) / 2 dct = {(0): [0, 0]} for i in lst: dct[i] = [0, 0] for i in range(n): if i % 2 == 0: dct[lst[i]][0] += 1 else: dct[lst[i]][1] +=...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR DICT NUMBER LIST NUMBER NUMBER FOR VAR VA...
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful. Therefore, Sasha decided ...
def main(): n = int(input()) a = map(int, input().split()) cnt = [{} for _ in range(2)] xor = 0 result = 0 cnt[1][0] = 1 for i, x in enumerate(a): xor ^= x index = i & 1 result += int(cnt[index].get(xor) or 0) cnt[index][xor] = int(cnt[index].get(xor) or 0) + ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUM...
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful. Therefore, Sasha decided ...
n = int(input()) a = list(map(int, input().split())) xor = [a[0]] for i in range(1, n): xor.append(xor[-1] ^ a[i]) d = {(0): [1, 0]} for i in range(n): if xor[i] not in d: d[xor[i]] = [0, 0] d[xor[i]][(i + 1) % 2] += 1 funny = 0 for k in d: odd = d[k][1] even = d[k][0] funny += odd * (od...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR DICT NUMBER LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR LIST NU...
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful. Therefore, Sasha decided ...
n = int(input()) arr = list(map(int, input().split())) pre = [0] * (n + 1) for i in range(n): pre[i + 1] = pre[i] ^ arr[i] d = {} d1 = {} for i in range(n + 1): if i % 2 == 0: if pre[i] in d: d[pre[i]] += 1 else: d[pre[i]] = 1 elif pre[i] in d1: d1[pre[i]] += ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NU...
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful. Therefore, Sasha decided ...
n = int(input()) a = list(map(int, input().split())) d0 = {} d1 = {} cx = 0 ans = 0 for i in range(n): cx = cx ^ a[i] if cx == 0 and i % 2 == 1: ans += 1 if i % 2 == 1: ans += d1.get(cx, 0) if cx not in d1: d1[cx] = 0 d1[cx] += 1 else: ans += d0.get(cx...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR FUNC_CAL...
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful. Therefore, Sasha decided ...
input() N = 1 << 20 d = [1] + [0] * N, [0] * N r = s = i = 0 for x in map(int, input().split()): s ^= x i ^= 1 r += d[i][s] d[i][s] += 1 print(r)
EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful. Therefore, Sasha decided ...
n = int(input()) a = [int(x) for x in input().split()] pref = [0] for i in range(n): pref.append(pref[-1] ^ a[i]) dp = [[(0) for i in range(2**20 + 5)] for j in range(2)] ans = 0 for i in range(len(pref)): ans += dp[i % 2][pref[i]] dp[i % 2][pref[i]] += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CAL...
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful. Therefore, Sasha decided ...
n = int(input()) arr_str = input().split() arr = [int(x) for x in arr_str] cum_sum_arr = [] cum_sum_arr.append(0) cum_sum = 0 for i in range(0, len(arr)): cum_sum = cum_sum ^ arr[i] cum_sum_arr.append(cum_sum) count_pair = 0 sum2ind_odd = dict() sum2ind_even = dict() sum2ind_even[0] = 1 for r in range(1, len(cu...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN...
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful. Therefore, Sasha decided ...
n = int(input()) a = [int(i) for i in input().split(" ")] class SegmentTree(object): def __init__(self, nums): self.n = len(nums) self.tree = [0] * (2 * self.n) def buildTree(nums): self.tree[self.n :] = nums[:] for i in range(self.n - 1, 0, -1): s...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING CLASS_DEF VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR FUNC_DEF ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP NU...
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful. Therefore, Sasha decided ...
n = int(input()) arr = list(map(int, input().strip().split())) mp = {} pre = [0] * n pre[0] = arr[0] for i in range(1, n): pre[i] = pre[i - 1] ^ arr[i] ans = 0 for i in range(n): x = 0 ^ pre[i] if x in mp: ans += mp[x][(i + 1) % 2] if pre[i] == 0: if (i + 1) % 2 == 0: ans += ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR ...
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful. Therefore, Sasha decided ...
input() d = {(0, 0): 1} s = i = 0 for x in map(int, input().split()): s ^= x i ^= 1 d[s, i] = d.get((s, i), 0) + 1 print(sum(d[x] * (d[x] - 1) // 2 for x in d))
EXPR FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR