description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
t = int(input()) while t: t -= 1 n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) s00 = abs(a[0] - b[0]) s11 = abs(a[-1] - b[-1]) s01 = abs(a[0] - b[-1]) s10 = abs(a[-1] - b[0]) sa0 = min(abs(i - b[0]) for i in a) sa1 = min(abs(i - b[-1]) f...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP V...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) arr2 = list(map(int, input().split())) cost_00 = min([abs(arr[0] - i) for i in arr2]) cost_01 = min([abs(arr[-1] - i) for i in arr2]) cost_10 = min([abs(arr2[0] - i) for i in arr]) cost_11 = min([abs(arr2[-1...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUN...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) z1 = abs(a[-1] - b[0]) z2 = abs(a[0] - b[-1]) a1 = abs(a[-1] - b[-1]) a2 = abs(a[0] - b[0]) m3 = m1 = a1 m4 = m2 = a2 for i in range(n): d1 = abs(a[i] - ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
for _ in range(int(input())): n = int(input()) a = (*map(int, input().split()),) b = (*map(int, input().split()),) ans1 = abs(a[0] - b[0]) + abs(a[-1] - b[-1]) ans2 = abs(a[0] - b[-1]) + abs(a[-1] - b[0]) ans3 = ( abs(a[0] - b[0]) + min(abs(a[-1] - b[i]) for i in range(n)) ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUN...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
def find_smallest(va, vb, id): ret = 1000000000 for b in vb: n = abs(va[id] - b) if n < ret: ret = n return ret for i in range(int(input())): n = int(input()) a = [] b = [] line = input().split() for j in range(n): a.append(int(line[j])) line = i...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR...
Under a grammar given below, strings can represent a set of lowercase words.  Let's use R(expr) to denote the set of words the expression represents. Grammar can best be understood through simple examples: Single letters represent a singleton set containing that word. R("a") = {"a"} R("w") = {"w"} When we t...
class Solution: def braceExpansionII(self, expression: str) -> List[str]: stack, res, cur = [], [], [""] for v in expression: if v.isalpha(): cur = [(c + v) for c in cur] elif v == ",": res += cur cur = [""] elif v ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR VAR VAR LIST LIST LIST STRING FOR VAR VAR IF FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR STRING VAR VAR ASSIGN VAR LIST STRING IF VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST LIST STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_C...
Under a grammar given below, strings can represent a set of lowercase words.  Let's use R(expr) to denote the set of words the expression represents. Grammar can best be understood through simple examples: Single letters represent a singleton set containing that word. R("a") = {"a"} R("w") = {"w"} When we t...
class Solution: def braceExpansionII(self, expression: str) -> List[str]: groups = [[]] level = 0 for i, c in enumerate(expression): if c == "{": if level == 0: start = i + 1 level += 1 elif c == "}": ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR LIST LIST ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR LIST IF VAR NUMBER EXPR F...
Under a grammar given below, strings can represent a set of lowercase words.  Let's use R(expr) to denote the set of words the expression represents. Grammar can best be understood through simple examples: Single letters represent a singleton set containing that word. R("a") = {"a"} R("w") = {"w"} When we t...
class Solution: def braceExpansionII(self, expression: str) -> List[str]: stack, res, cur = [], [], [""] for i, v in enumerate(expression): print(v) print(stack) print(res, cur) if v.isalpha(): cur = [(c + v) for c in cur] ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR VAR VAR LIST LIST LIST STRING FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST LIST STRING IF VAR STR...
Under a grammar given below, strings can represent a set of lowercase words.  Let's use R(expr) to denote the set of words the expression represents. Grammar can best be understood through simple examples: Single letters represent a singleton set containing that word. R("a") = {"a"} R("w") = {"w"} When we t...
class Solution: def braceExpansionII(self, expression: str) -> List[str]: stack = [] for letter in expression: if letter.isalpha(): stack.append(set(letter)) elif letter == "{": stack.append("{") elif letter == ",": ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR STRING IF VAR STRING EXPR FUNC_CALL VAR STRING IF VAR STRING WHILE VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VA...
Under a grammar given below, strings can represent a set of lowercase words.  Let's use R(expr) to denote the set of words the expression represents. Grammar can best be understood through simple examples: Single letters represent a singleton set containing that word. R("a") = {"a"} R("w") = {"w"} When we t...
class Solution: def braceExpansionII(self, expression: str) -> List[str]: stack = [] prev = set() curr = set() for s in expression: if s == "{": stack.append(prev) stack.append(curr) curr = set() prev = set(...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR LIST STRING FOR VAR BIN_OP VAR VA...
A Hamiltonian path, is a path in an undirected graph that visits each vertex exactly once. Given an undirected graph, the task is to check if a Hamiltonian path is present in it or not. Example 1: Input: N = 4, M = 4 Edges[][]= { {1,2}, {2,3}, {3,4}, {2,4} } Output: 1 Explanation: There is a hamiltonian path: 1 -> 2...
class Solution: def check(self, N, M, Edges): adj = [[] for i in range(N)] for edge in Edges: adj[edge[0] - 1].append(edge[1] - 1) adj[edge[1] - 1].append(edge[0] - 1) for node in range(N): visited = set() if self.check_util(N, M, adj, node, v...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMB...
A Hamiltonian path, is a path in an undirected graph that visits each vertex exactly once. Given an undirected graph, the task is to check if a Hamiltonian path is present in it or not. Example 1: Input: N = 4, M = 4 Edges[][]= { {1,2}, {2,3}, {3,4}, {2,4} } Output: 1 Explanation: There is a hamiltonian path: 1 -> 2...
class Solution: def check(self, N, M, Edges): adj = [[] for _ in range(N + 1)] for i in range(M): adj[Edges[i][0]].append(Edges[i][1]) adj[Edges[i][1]].append(Edges[i][0]) visit = [0] * (N + 1) ans = [False] * 1 def fun(i, c): if c == N -...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_DEF IF VAR BIN_OP VAR NUMBER ASSIGN...
Given Preorder, Inorder and Postorder traversals of some tree of size N. The task is to check if they are all of the same tree or not. Example 1: Input: N = 5 preorder[] = {1, 2, 4, 5, 3} inorder[] = {4, 2, 5, 1, 3} postorder[] = {4, 5, 2, 3, 1} Output: Yes Explanation: All of the above three traversals are of the sa...
class Node: def __init__(self, val): self.data = val self.left = None self.right = None class Solution: def checktree(self, preorder, inorder, postorde, N): def postorder(root): if root is None: return [] return postorder(root.left) + ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NONE RETURN LIST RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR LIST VAR FUNC_DEF NUMBER NUMBER BIN_OP VAR NUMBER IF VAR VAR RETURN NONE VAR ASSIGN VAR VAR VAR ASSIGN VAR NONE FOR VAR FUNC_CALL VAR VAR BIN_OP ...
Given Preorder, Inorder and Postorder traversals of some tree of size N. The task is to check if they are all of the same tree or not. Example 1: Input: N = 5 preorder[] = {1, 2, 4, 5, 3} inorder[] = {4, 2, 5, 1, 3} postorder[] = {4, 5, 2, 3, 1} Output: Yes Explanation: All of the above three traversals are of the sa...
class Node: def __init__(self, data, left=None, right=None): self.data = data self.left = left self.right = right class Solution: def checktree(self, preorder, inorder, postorder, N): def postOrder(root): if root: postOrder(root.left) ...
CLASS_DEF FUNC_DEF NONE NONE ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR CLASS_DEF FUNC_DEF FUNC_DEF IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR VAR VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR...
Given Preorder, Inorder and Postorder traversals of some tree of size N. The task is to check if they are all of the same tree or not. Example 1: Input: N = 5 preorder[] = {1, 2, 4, 5, 3} inorder[] = {4, 2, 5, 1, 3} postorder[] = {4, 5, 2, 3, 1} Output: Yes Explanation: All of the above three traversals are of the sa...
class Node: def __init__(self, d): self.data = d self.left = None self.right = None class Solution: def checktree(self, preorder, inorder, postorder, N): m = {} for i in range(N): m[inorder[i]] = i l = [0] def construct(st, end): ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST NUMBER FUNC_DEF IF VAR VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VA...
Given Preorder, Inorder and Postorder traversals of some tree of size N. The task is to check if they are all of the same tree or not. Example 1: Input: N = 5 preorder[] = {1, 2, 4, 5, 3} inorder[] = {4, 2, 5, 1, 3} postorder[] = {4, 5, 2, 3, 1} Output: Yes Explanation: All of the above three traversals are of the sa...
class Node: def __init__(self, val): self.val = val self.left = self.right = None class Solution: def build(self, pre, ino): tem = [True] n = len(pre) def rec(st, en, n): if st > en or ind[0] >= n or tem[0] == None: return nod ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR NONE CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR VAR NUMBER VAR VAR NUMBER NONE RETURN ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR...
Given Preorder, Inorder and Postorder traversals of some tree of size N. The task is to check if they are all of the same tree or not. Example 1: Input: N = 5 preorder[] = {1, 2, 4, 5, 3} inorder[] = {4, 2, 5, 1, 3} postorder[] = {4, 5, 2, 3, 1} Output: Yes Explanation: All of the above three traversals are of the sa...
class Solution: def checktree(self, preorder, inorder, postorder, N): if N == 0: return True if N == 1: return preorder[0] == postorder[0] and postorder[0] == inorder[0] root = preorder[0] if root != postorder[N - 1]: return False if root ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN FUNC_CALL VAR...
Given Preorder, Inorder and Postorder traversals of some tree of size N. The task is to check if they are all of the same tree or not. Example 1: Input: N = 5 preorder[] = {1, 2, 4, 5, 3} inorder[] = {4, 2, 5, 1, 3} postorder[] = {4, 5, 2, 3, 1} Output: Yes Explanation: All of the above three traversals are of the sa...
class Solution: def checktree(self, preorder, inorder, postorder, N): if N == 0: return 1 if N == 1: return preorder[0] == inorder[0] and inorder[0] == postorder[0] idx = -1 for i in range(N): if inorder[i] == preorder[0]: idx = i ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR A...
Given Preorder, Inorder and Postorder traversals of some tree of size N. The task is to check if they are all of the same tree or not. Example 1: Input: N = 5 preorder[] = {1, 2, 4, 5, 3} inorder[] = {4, 2, 5, 1, 3} postorder[] = {4, 5, 2, 3, 1} Output: Yes Explanation: All of the above three traversals are of the sa...
class Node: def __init__(self, val): self.data = val self.left = None self.right = None class Solution: def checktree(self, preorder, inorder, postorder, N): inorder_map = {inorder[i]: i for i in range(len(inorder))} ind = [0] root = build(preorder, ind, 0, le...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ...
Given Preorder, Inorder and Postorder traversals of some tree of size N. The task is to check if they are all of the same tree or not. Example 1: Input: N = 5 preorder[] = {1, 2, 4, 5, 3} inorder[] = {4, 2, 5, 1, 3} postorder[] = {4, 5, 2, 3, 1} Output: Yes Explanation: All of the above three traversals are of the sa...
class Solution: def checktree(self, preorder, inorder, postorder, N): if N == 0: return True if preorder[0] != postorder[-1]: return False root = preorder[0] if root not in inorder: return False else: p = inorder.index(preorder...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ...
Given Preorder, Inorder and Postorder traversals of some tree of size N. The task is to check if they are all of the same tree or not. Example 1: Input: N = 5 preorder[] = {1, 2, 4, 5, 3} inorder[] = {4, 2, 5, 1, 3} postorder[] = {4, 5, 2, 3, 1} Output: Yes Explanation: All of the above three traversals are of the sa...
class Solution: def checktreeutil(self, preorder, inorder, postorder): if len(preorder) >= 1 and len(postorder) >= 1 and len(inorder) >= 1: if len(preorder) != len(postorder): return False temp = -10000000 for i in range(len(inorder)): if ...
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR N...
Given Preorder, Inorder and Postorder traversals of some tree of size N. The task is to check if they are all of the same tree or not. Example 1: Input: N = 5 preorder[] = {1, 2, 4, 5, 3} inorder[] = {4, 2, 5, 1, 3} postorder[] = {4, 5, 2, 3, 1} Output: Yes Explanation: All of the above three traversals are of the sa...
class Node: def __init__(self, data): self.data = data self.left = None self.right = None class Solution: def post(self, root, crr): if root == None: return self.post(root.left, crr) self.post(root.right, crr) crr.append(root.data) ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE CLASS_DEF FUNC_DEF IF VAR NONE RETURN EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER VAR VAR VAR RETURN NONE ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN V...
Given Preorder, Inorder and Postorder traversals of some tree of size N. The task is to check if they are all of the same tree or not. Example 1: Input: N = 5 preorder[] = {1, 2, 4, 5, 3} inorder[] = {4, 2, 5, 1, 3} postorder[] = {4, 5, 2, 3, 1} Output: Yes Explanation: All of the above three traversals are of the sa...
class Solution: def checktree(self, preorder, inorder, postorder, N): def f(inord, pre, st, en, i, n, d, arr): if st > en or i[0] >= n: return pos = d[pre[i[0]]] val = pre[i[0]] i[0] += 1 f(inord, pre, st, pos - 1, i, n, d, arr) ...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR VAR NUMBER VAR RETURN ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR LIST VAR ASSIGN VAR LIST NUMBER ASSIGN VAR DICT FOR...
Given Preorder, Inorder and Postorder traversals of some tree of size N. The task is to check if they are all of the same tree or not. Example 1: Input: N = 5 preorder[] = {1, 2, 4, 5, 3} inorder[] = {4, 2, 5, 1, 3} postorder[] = {4, 5, 2, 3, 1} Output: Yes Explanation: All of the above three traversals are of the sa...
class Solution: def checktree(self, preorder, inorder, postorder, N): if not preorder and not inorder and not postorder: return True if ( len(preorder) != len(inorder) or len(inorder) != len(postorder) or len(postorder) != len(preorder) ): ...
CLASS_DEF FUNC_DEF IF VAR VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR NU...
Given Preorder, Inorder and Postorder traversals of some tree of size N. The task is to check if they are all of the same tree or not. Example 1: Input: N = 5 preorder[] = {1, 2, 4, 5, 3} inorder[] = {4, 2, 5, 1, 3} postorder[] = {4, 5, 2, 3, 1} Output: Yes Explanation: All of the above three traversals are of the sa...
class Node: def __init__(self, data): self.left = None self.data = data self.right = None class Solution: def Search(self, start, end, inorder, val): for i in range(start, end + 1): if inorder[i] == val: return i return -1 def Construc...
CLASS_DEF FUNC_DEF ASSIGN VAR NONE ASSIGN VAR VAR ASSIGN VAR NONE CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR RETURN VAR RETURN NUMBER FUNC_DEF IF VAR VAR RETURN NONE IF VAR NUMBER VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMB...
Given Preorder, Inorder and Postorder traversals of some tree of size N. The task is to check if they are all of the same tree or not. Example 1: Input: N = 5 preorder[] = {1, 2, 4, 5, 3} inorder[] = {4, 2, 5, 1, 3} postorder[] = {4, 5, 2, 3, 1} Output: Yes Explanation: All of the above three traversals are of the sa...
class Tree: def __init__(self, data): self.data = data self.left = None self.right = None class Solution: def checktree(self, preorder, inorder, postorder, N): flag = [False] def rec1(a, b): if flag[0]: return None if not a: ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER FUNC_DEF IF VAR NUMBER RETURN NONE IF VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER NUMBER RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL...
Given Preorder, Inorder and Postorder traversals of some tree of size N. The task is to check if they are all of the same tree or not. Example 1: Input: N = 5 preorder[] = {1, 2, 4, 5, 3} inorder[] = {4, 2, 5, 1, 3} postorder[] = {4, 5, 2, 3, 1} Output: Yes Explanation: All of the above three traversals are of the sa...
class Solution: def check(self, pre, l1, r1, ino, l2, r2, post, l3, r3): if l2 > r2: return True if pre[l1] != post[r3]: return False try: idx = ino.index(pre[l1]) except ValueError: return False return self.check( ...
CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER...
Given Preorder, Inorder and Postorder traversals of some tree of size N. The task is to check if they are all of the same tree or not. Example 1: Input: N = 5 preorder[] = {1, 2, 4, 5, 3} inorder[] = {4, 2, 5, 1, 3} postorder[] = {4, 5, 2, 3, 1} Output: Yes Explanation: All of the above three traversals are of the sa...
class node: def __init__(self, v): self.val = v self.left = None self.right = None class Solution: def checktree(self, pr, io, po, n): valid = True def f(pr, io): nonlocal valid if not valid: return if len(pr) == 0 ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FUNC_DEF IF VAR RETURN IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR ASSIGN VAR NUMBER RETURN IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMB...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
matches = 0 def match_counter(hour, mins, matches): for m in range(mins): if m == hour and str(m)[0] == str(hour)[-1] or m * 11 == hour: matches += 1 elif m == hour * 11: matches += 1 break return matches def hours_counters(hours, mins, matches): for h...
ASSIGN VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CA...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
import sys input = sys.stdin.readline def inp(): return int(input()) def inlt(): return list(map(int, input().split())) def insr(): return input().strip() def invr(): return map(int, input().split()) def outp(n): sys.stdout.write(str(n) + "\n") def outlt(lst): sys.stdout.write(" ".j...
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING FUNC_DEF EXPR FUNC_CALL ...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
t = int(input()) for i in range(t): time = list(map(int, input().split())) hours = time[0] minutes = time[1] clock = 0 for i in range(hours): for j in range(minutes): x = str(i) + str(j) if x.count(x[0]) == len(x): clock += 1 print(clock)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
t = int(input()) for i in range(t): n, m = map(int, input().split()) s = min(n, m) ans = 0 if s > 9: ans += 10 else: ans += s for j in range(1, n): if j * 11 < m: ans += 1 for k in range(1, m): if k * 11 < n: ans += 1 a = int((n - 1...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VA...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
for _ in range(int(input())): hour, minute = map(int, input().split()) count = 0 for h in range(hour): for m in range(minute): time = str(h) + str(m) if time.count(time[0]) == len(time): count = count + 1 print(count)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
for _ in range(int(input())): h, m = map(int, input().split()) coun = 0 for i in range(h): for j in range(m): a, b = [], [] a.extend(str(i)) b.extend(str(j)) if set(a) == set(b) and len(set(a)) == 1: coun += 1 print(coun)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST LIST EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
for _ in range(int(input())): h, m = map(int, input().split()) ele_cnt = 0 for i in range(0, h): for j in range(0, m): x = str(i) y = str(j) time = x + ":" + y if time.count(time[0]) == len(time) - 1: ele_cnt += 1 print(ele_cnt)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR STRING VAR IF FUNC_CALL VAR VAR NUMBER BIN...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
def identical(h, m): ans = 0 for hr in range(h): for min in range(m): if hr < 10 and min < 10: if hr == min: ans += 1 elif hr < 10 and min >= 10: if hr * 11 == min: ans += 1 elif hr >= 10 and min ...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR NUMB...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
fine = [11, 22, 33, 44, 55, 66, 77, 88, 99] t = int(input()) for _ in range(t): l = input().split() h = int(l[0]) m = int(l[1]) th = list() tm = list() for i in range(h): if i <= 9: th.append(i) elif i in fine: th.append(i) for i in range(m): i...
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL V...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
def reloj(hora=0, minuto=0): arr_str = [] if hora > 100: hora = 100 if minuto > 100: minuto = 100 for i in range(hora): for j in range(minuto): arr_str.append(f"{i}:{j}") c = 0 arr_2 = [] for i in arr_str: if len(set(i)) == 2: c += 1 ...
FUNC_DEF NUMBER NUMBER ASSIGN VAR LIST IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL ...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
tests = int(input()) for i in range(tests): h, m = map(int, input().split()) ans = 1 for j in range(1, h): if j < 10 or j % 11 == 0: num = j % 10 if num < m: ans += 1 count = 1 while num * (10**count + 1) < m: ans += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP BIN_OP NUMBER V...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
def getCount(h, m, i): h = int(h) m = int(m) h1 = 0 lst = [11, 22, 33, 44, 55, 66, 77, 88, 99] while h1 < h: for m1 in range(0, m): if h1 < 10: if m1 < 10 and h1 == m1: count[i] += 1 if m1 in lst and m1 % 10 == h1: ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER WHILE VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
test = int(input()) for _ in range(test): a, b = map(int, input().split()) c = 0 for j in range(0, a): for k in range(0, b): if len(list(set(str(j)))) == 1 and len(list(set(str(k)))) == 1: l = str(j) + str(k) if l == l[::-1]: c = c + 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FU...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
t = int(input()) h = [] m = [] for i in range(t): value = input() inputs = value.split(" ") h.append(int(inputs[0])) m.append(int(inputs[1])) def dig(h, m): count = 0 hou = "" mins = "" for i in range(0, h): hou = str(i) for j in range(0, m): mins = str(j) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CA...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
t = int(input()) for i in range(t): hours, minutes = map(int, input().split()) count = 1 i = 1 while i <= 9 and i < hours: if i < minutes: count += 1 if i * 10 + i < minutes: count += 1 i += 1 i = 11 while i <= 99 and i < hours: if i < minu...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR IF VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR IF VAR VAR VAR...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
t = int(input()) for _ in range(t): h, m = map(int, input().split()) cnt = 0 for i in range(h): for j in range(m): cnt += 1 s = str(i) + str(j) for k in s: if k != s[0]: cnt -= 1 break print(cnt)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
t = int(input()) for _ in range(t): h, m = map(int, input().split()) count = 0 for i in range(0, h): for j in range(0, m): if len(str(i)) < 2 and len(str(j)) < 2: if i == j: count += 1 elif len(str(i)) < 2 and len(str(j)) == 2: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER IF FUNC_CAL...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
for _ in range(int(input())): n, m = map(int, input().split()) count = 0 for i in range(n): i = str(i) if len(i) == 1 or i[0] == i[1]: for j in range(m): j = str(j) if len(j) == 1 or j[0] == j[1]: if i[0] == j[0]: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUM...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
t = int(input()) for _ in range(t): h, m = [int(i) for i in input().split()] iden_time = 0 for i in range(h): if i < 10: min = i if min < m: iden_time += 1 if i > 0: min = i * 10 + i if min < m: i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR VAR NUMBER IF VAR NUMBER BIN_OP VA...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
t = int(input()) while t > 0: h, m = map(int, input().split()) a = 0 for i in range(h): if i <= 9 or i % 10 == i // 10: for j in range(m): if j <= 9 or j % 10 == j // 10: if j % 10 == i % 10: a += 1 print(a) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBE...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
times = [(0, 0)] h = m = 1 while h < 10: times.append((h, m)) times.append((h * 11, m)) times.append((h, m * 11)) times.append((h * 11, m * 11)) h = h + 1 m = h t = int(input()) while t: h, m = [int(i) for i in input().split()] num = 0 for i in times: if i[0] < h and i[1] < m...
ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHIL...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
for _ in range(int(input())): h, m = map(int, input().split()) H = h - 1 M = m - 1 print(min(M, H, 9) + 1 + min(H, M // 11) + min(M, H // 11) + min(H // 11, M // 11))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
for _ in range(int(input())): count = 0 HM = list(map(int, input().split())) for i in range(HM[0]): if i <= 9 or i % 11 == 0: for j in range(HM[1]): if j <= 9 and i % 11 == j != 0: count += 1 elif j / 11 == i != 0 or i / 11 == j != 0: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR N...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
def is_ident(hr, min): quer = str(hr) + str(min) for i in quer: if i == quer[0]: pass else: return False return True def main(): t = int(input()) while t > 0: hr, min = map(int, input().split()) count = 0 for x in range(hr): ...
FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF FUNC...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
t = int(input()) while t: h, m = map(int, input().strip().split()) i = 0 j = 0 f = 0 c = 0 for i in range(h): if i < 10 or i % 11 == 0: for j in range(m): if (j < 10 or j % 11 == 0) and str(i)[0] == str(j)[0]: f = 1 c += f ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER FU...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
t = int(input()) if 1 <= t <= 50: for _ in range(t): h, m = map(int, input().split()) if 1 <= h <= 100 and 1 <= m <= 100: i = 1 c = 1 while i <= 9: if 0 <= i <= h - 1 and 0 <= 11 * i <= m - 1: c = c + 1 if 0 <= 1...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF NUMBER VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
t = int(input()) while t: h, m = map(int, input().split()) i = 1 count = 0 while i <= 9 and i <= h - 1: if i <= m - 1: count = count + 1 if i * 11 <= m - 1: count = count + 1 if i * 11 <= h - 1 and i <= m - 1: count = count + 1 if i * 1...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUM...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
T = int(input()) while T: hour, mins = [int(x) for x in input().split()] count = 0 for i in range(hour): for j in range(mins): if len(set(str(i) + str(j))) == 1: count += 1 print(count) T -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
t = int(input()) for inh in range(0, t): h, m = map(int, input().split()) ans = 1 uni, bi = 1, 11 while uni <= 9: a, b = 0, 0 if uni < h: a += 1 if bi < h: a += 1 if uni < m: b += 1 if bi < m: b += 1 if a == ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR NUM...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
for _ in range(int(input())): h, m = map(int, input().split()) def fun(v): v = str(v) d = [] if len(v) == 1: d.append(int(v[0])) else: if int(v[0]) <= int(v[1]): d.append(int(v[0])) else: d.append(int(v[0]) - 1)...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR V...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
n = int(input()) while n > 0: h, m = map(int, input().split()) count = 0 for i in range(h): for j in range(m): x = set(list(str(i))) y = set(list(str(j))) if len(x) == 1 and len(y) == 1 and x == y: count += 1 print(count) n -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NU...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
for t in range(int(input())): h, m = [int(x) for x in input().split(" ")] count = 1 for i in range(1, h): if i % 11 == 0 or i < 10: temp = i % 10 while temp < m: count += 1 temp = temp * 10 + i % 10 print(count)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
for _ in range(int(input())): h, m = map(int, input().split()) ans = min(10, min(h, m)) if m % 11 == 0: ans += min(m // 11 - 1, h - 1) else: ans += min(m // 11, h - 1) if h % 11 == 0: for i in range(1, h // 11): if 11 * i < m: ans += 2 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
for _ in range(int(input())): H, M = map(int, input().split()) count = 0 for i in range(H): for j in range(M): if i <= 9 and j <= 9 and i == j: count += 1 elif i <= 9 and j > 10: x = j % 10 y = j // 10 if i == x ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR V...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 3:33 It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are...
case = int(input()) for i in range(case): h, m = map(int, input().split(" ")) h = h - 1 m = m - 1 hl = len(str(h)) ml = len(str(m)) final_sum = 1 for i in range(1, 10): ans = "" n = hl while n > 0: ans = ans + str(i) n -= 1 if int(ans) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ...
Write a program to solve a Sudoku puzzle by filling the empty cells. A sudoku solution must satisfy all of the following rules: Each of the digits 1-9 must occur exactly once in each row. Each of the digits 1-9 must occur exactly once in each column. Each of the the digits 1-9 must occur exactly...
class Solution: full_values = set("123456789") def findValues(self, board, row, col): row_start = row // 3 * 3 col_start = col // 3 * 3 values = self.full_values - ( set(board[row]) | {board[i][col] for i in range(9)} | { board[i][j] ...
CLASS_DEF ASSIGN VAR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUM...
Write a program to solve a Sudoku puzzle by filling the empty cells. A sudoku solution must satisfy all of the following rules: Each of the digits 1-9 must occur exactly once in each row. Each of the digits 1-9 must occur exactly once in each column. Each of the the digits 1-9 must occur exactly...
class Solution(object): def __init__(self): self.filled = [] def solveSudoku(self, board): pln = [] for i in range(9): pln.append([]) self.filled.append([]) for j in range(9): if board[i][j].isdigit(): self.filled[...
CLASS_DEF VAR FUNC_DEF ASSIGN VAR LIST FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR LIST EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ...
Write a program to solve a Sudoku puzzle by filling the empty cells. A sudoku solution must satisfy all of the following rules: Each of the digits 1-9 must occur exactly once in each row. Each of the digits 1-9 must occur exactly once in each column. Each of the the digits 1-9 must occur exactly...
class Solution: def reduceSingleOption(self, board, emptyGrid, valid): m = 1 while m == 1: m = 10 for k in range(len(emptyGrid) - 1, -1, -1): i, j = emptyGrid[k] option = set.intersection( valid[i], valid[j + 9], valid[i //...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF VAR RETURN IF FUNC_CALL ...
Write a program to solve a Sudoku puzzle by filling the empty cells. A sudoku solution must satisfy all of the following rules: Each of the digits 1-9 must occur exactly once in each row. Each of the digits 1-9 must occur exactly once in each column. Each of the the digits 1-9 must occur exactly...
class Solution: def FindValid(self): a = "123456789" d, val = {}, {} for i in range(9): for j in range(9): temp = self.board[i][j] if temp != ".": d["r", i] = d.get(("r", i), []) + [temp] d["c", j] = d.get((...
CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR VAR DICT DICT FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR STRING ASSIGN VAR STRING VAR BIN_OP FUNC_CALL VAR STRING VAR LIST LIST VAR ASSIGN VAR STRING VAR BIN_OP FUNC_CALL VAR STRING VAR LIST LIST VAR ASSIGN VAR BIN_OP VAR NUMBE...
Write a program to solve a Sudoku puzzle by filling the empty cells. A sudoku solution must satisfy all of the following rules: Each of the digits 1-9 must occur exactly once in each row. Each of the digits 1-9 must occur exactly once in each column. Each of the the digits 1-9 must occur exactly...
class Solution: def solveSudoku(self, board): self.board = board self.val = self.PossibleValue() self.Solver() def PossibleValue(self): nums = "123456789" d, val = {}, {} for i in range(9): for j in range(9): element = self.board[i][j...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR STRING ASSIGN VAR VAR DICT DICT FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR STRING ASSIGN VAR STRING VAR BIN_OP FUNC_CALL VAR STRING VAR LIST LIST VAR ASSIGN VAR STRING VAR BIN_O...
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image. Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image. To perform a "flood fill", consider the starting pixel, plus any...
class Solution: def dfs(self, row, col, ans, image, newColor, delRow, delCol, iniColor): ans[row][col] = newColor n, m = len(image), len(image[0]) for i in range(4): nrow, ncol = row + delRow[i], col + delCol[i] if ( nrow >= 0 and nrow...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_DEF ASSIG...
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image. Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image. To perform a "flood fill", consider the starting pixel, plus any...
class Solution: def floodFill(self, image, sr, sc, newColor): m = len(image) n = len(image[0]) startcolor = image[sr][sc] visited = [] for i in range(m): visited.append([0] * n) self.dfs(sr, sc, visited, image, newColor, startcolor) return image ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER I...
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image. Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image. To perform a "flood fill", consider the starting pixel, plus any...
class Solution: def floodFill(self, image, sr, sc, newColor): original_color = image[sr][sc] if original_color == newColor: return image def fill(image, row, col): if ( row < 0 or row >= len(image) or col < 0 ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR IF VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR RETURN ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR N...
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image. Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image. To perform a "flood fill", consider the starting pixel, plus any...
class Solution: def floodFill(self, image, sr, sc, newColor): def dfs(ans, image, inicolor, newcolor, nrow, ncol, sr, sc): n = len(image) m = len(image[0]) ans[sr][sc] = newcolor for i in range(4): nsr = sr + nrow[i] nsc = sc ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR...
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image. Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image. To perform a "flood fill", consider the starting pixel, plus any...
class Solution: def floodFill(self, image, sr, sc, color): r = len(image) c = len(image[0]) def dfs(i, j): if ( i < 0 or j < 0 or i >= r or j >= c or image[i][j] == color or image[i]...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR RETURN ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER E...
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image. Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image. To perform a "flood fill", consider the starting pixel, plus any...
import itertools class Solution: def floodFill(self, image, sr, sc, newColor): ans = image iniColor = image[sr][sc] n = len(image) m = len(image[0]) delRow = [-1, 0, +1, 0] delCol = [0, +1, 0, -1] visited = [[None for _ in range(m)] for _ in range(n)] ...
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NONE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR ASSIGN VAR ...
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image. Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image. To perform a "flood fill", consider the starting pixel, plus any...
class Solution: def floodFill(self, image, sr, sc, newColor): def perform(a, b, visited=set()): if (a, b) in visited: return if a < 0 or b < 0: return if a >= len(image) or b >= len(image[0]): return if image[a...
CLASS_DEF FUNC_DEF FUNC_DEF FUNC_CALL VAR IF VAR VAR VAR RETURN IF VAR NUMBER VAR NUMBER RETURN IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER RETURN IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR...
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image. Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image. To perform a "flood fill", consider the starting pixel, plus any...
class Solution: def floodFill(self, image, sr, sc, newColor): initclr = image[sr][sc] new_image = image srn = len(image) scn = len(image[0]) delsr = [-1, +1, 0, 0] delsc = [0, 0, +1, -1] def dfs(image, sr, sc, new_image, newcolor, initclr): new_i...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP V...
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image. Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image. To perform a "flood fill", consider the starting pixel, plus any...
class Solution: def dfs(self, grid, i, j, newColor, val): if ( i >= 0 and i < len(grid) and j >= 0 and j < len(grid[i]) and grid[i][j] == val ): grid[i][j] = newColor self.dfs(grid, i - 1, j, newColor, val) ...
CLASS_DEF FUNC_DEF IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN...
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image. Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image. To perform a "flood fill", consider the starting pixel, plus any...
class Solution: def floodFill(self, image, sr, sc, newColor): def dfs(image, sr, sc, newColor, srl, scl, source): if sr < 0 or sr >= srl or sc < 0 or sc >= scl: return if image[sr][sc] != source: return image[sr][sc] = newColor ...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR RETURN IF VAR VAR VAR VAR RETURN ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CA...
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image. Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image. To perform a "flood fill", consider the starting pixel, plus any...
class Solution: def floodFill(self, image, sr, sc, newColor): mycolor = image[sr][sc] def helper(sr, sc): if sr < 0 or sr >= len(image) or sc < 0 or sc >= len(image[0]): return if image[sr][sc] != mycolor: return if image[sr][sc] ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_DEF IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER RETURN IF VAR VAR VAR VAR RETURN IF VAR VAR VAR VAR RETURN ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP...
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image. Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image. To perform a "flood fill", consider the starting pixel, plus any...
class Solution: def floodFill(self, image, sr, sc, newColor): sourceColor = image[sr][sc] if newColor == sourceColor: return image self.dfs(image, sr, sc, sourceColor, newColor) return image def dfs(self, image, sr, sc, sourceColor, newColor): if ( ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR IF VAR VAR RETURN VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF IF NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VA...
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image. Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image. To perform a "flood fill", consider the starting pixel, plus any...
class Solution: def floodFill(self, image, sr, sc, newColor): row = len(image) col = len(image[0]) directions = [[0, 1], [1, 0], [0, -1], [-1, 0]] visited = [[(-1) for _ in range(col)] for _ in range(row)] queue = [(sr, sc, image[sr][sc])] visited[sr][sc] = 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER WHILE VAR ASSIGN VAR...
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image. Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image. To perform a "flood fill", consider the starting pixel, plus any...
class Solution: def floodFill(self, image, sr, sc, color): def dfs(sr, sc, image, color, row, cols, source): if sr >= row or sr < 0 or sc >= cols or sc < 0: return if image[sr][sc] != source: return image[sr][sc] = color dfs(s...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN IF VAR VAR VAR VAR RETURN ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR EXPR FUNC_CA...
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image. Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image. To perform a "flood fill", consider the starting pixel, plus any...
class Solution: def dfs(self, image, i, j, m, n, oldColor, newColor, visited): if i < 0 or j < 0 or i >= m or j >= n: return if visited[i][j] == True: return visited[i][j] = True if image[i][j] != oldColor: return image[i][j] = newColor ...
CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR RETURN IF VAR VAR VAR NUMBER RETURN ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR VAR RETURN ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR ...
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image. Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image. To perform a "flood fill", consider the starting pixel, plus any...
class Solution: def floodFill(self, image, sr, sc, newColor): drow = [-1, 0, 1, 0] dcol = [0, 1, 0, -1] vis = [[(0) for i in range(len(image[0]))] for j in range(len(image))] m, n = len(image), len(image[0]) def bfs(vis, image, sr, sc, newColor, help): image[sr]...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ...
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image. Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image. To perform a "flood fill", consider the starting pixel, plus any...
class Solution: def floodFill(self, a, sr, sc, newColor): color = a[sr][sc] q = [(sr, sc)] a[sr][sc] = newColor vis = [[(0) for i in range(len(a[0]))] for i in range(len(a))] vis[sr][sc] = 1 while len(q) != 0: row, col = q.pop(0) for i in [-1,...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER FOR VAR LIST NUMBER NUMBER IF BIN_OP VAR ...
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image. Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image. To perform a "flood fill", consider the starting pixel, plus any...
class Solution: def floodFill(self, image, sr, sc, newColor): m, n = len(image), len(image[0]) origColor = image[sr][sc] if origColor == newColor: return image def dfs(row, col): if row < 0 or row >= m or col < 0 or col >= n: return ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR RETURN IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VA...
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image. Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image. To perform a "flood fill", consider the starting pixel, plus any...
class Solution: def floodFill(self, adj, sr, sc, newColor): x = len(adj[0]) y = len(adj) visited = [([0] * x) for i in range(y)] q = [[sr, sc]] ptr = 0 curr = adj[sr][sc] adj[sr][sc] = newColor visited[sr][sc] = 1 while ptr < len(q): ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST LIST VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_C...
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image. Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image. To perform a "flood fill", consider the starting pixel, plus any...
class Solution: def floodFill(self, image, sr, sc, newColor): src_pixel = image[sr][sc] self.helper(image, sr, sc, newColor, len(image), len(image[0]), src_pixel) return image def helper(self, image, cur_i, cur_j, newColor, rows, cols, src_pixel): if cur_i < 0 or cur_i >= rows:...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER VAR RETURN VAR FUNC_DEF IF VAR NUMBER VAR VAR RETURN IF VAR NUMBER VAR VAR RETURN IF VAR VAR VAR VAR RETURN IF VAR VAR VAR VAR RETURN ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VA...
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image. Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image. To perform a "flood fill", consider the starting pixel, plus any...
class Solution: def floodFill(self, image, sr, sc, newColor): def dfs(row, col, newColor, sr, sc, sourse, image): if sr < 0 or sr >= row or sc < 0 or sc >= col: return if sourse != image[sr][sc]: return else: image[sr][sc]...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR RETURN IF VAR VAR VAR VAR RETURN ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CA...
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image. Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image. To perform a "flood fill", consider the starting pixel, plus any...
class Solution: def floodFill(self, image, sr, sc, newColor): n = len(image) m = len(image[0]) ini = image[sr][sc] vis = [[(0) for j in range(m)] for i in range(n)] queue = [] queue.append((sr, sc)) vis[sr][sc] = 1 delrow = [-1, 0, 1, 0] delco...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER N...
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image. Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image. To perform a "flood fill", consider the starting pixel, plus any...
class Solution: def util(self, image, i, j, n, m, nc, c): if i < 0 or j < 0 or i >= n or j >= m or image[i][j] == nc: return if image[i][j] == c: image[i][j] = nc self.util(image, i + 1, j, n, m, nc, c) self.util(image, i, j + 1, n, m, nc, c) ...
CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR RETURN IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR EXPR FUNC_CA...
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image. Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image. To perform a "flood fill", consider the starting pixel, plus any...
class Solution: def floodFill(self, image, sr, sc, new): color = image[sr][sc] if color == new: return image def dfs(i, j): queue = [(i, j)] while len(queue): i, j = queue.pop() image[i][j] = new dirx = [-1...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR IF VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST VAR VAR WHILE FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ...
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image. Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image. To perform a "flood fill", consider the starting pixel, plus any...
class Solution: def floodFill(self, image, sr, sc, newColor): inicol = image[sr][sc] ans = [row[:] for row in image] delrow = [-1, 0, 1, 0] delcol = [0, 1, 0, -1] self.dfs(image, sr, sc, newColor, delrow, delcol, inicol, ans) return ans def dfs(self, image, row,...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR ...
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image. Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image. To perform a "flood fill", consider the starting pixel, plus any...
class Solution: def isValid(self, i, j, image, mapp, old, new): if ( i < 0 or j < 0 or i == len(image) or j == len(image[0]) or image[i][j] == new or (i, j) in mapp or image[i][j] not in [old, new] ): re...
CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR LIST VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST LIST VAR VAR WHILE VAR ASSIGN V...
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image. Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image. To perform a "flood fill", consider the starting pixel, plus any...
class Solution: def floodFill(self, image, sr, sc, newColor): seen = set() ROWS = len(image) COLS = len(image[0]) oldColor = image[sr][sc] def recursive(r, c, seen): if image[r][c] != oldColor: return image[r][c] = newColor ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_DEF IF VAR VAR VAR VAR RETURN ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_O...
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image. Given a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, "flood fill" the image. To perform a "flood fill", consider the starting pixel, plus any...
class Solution: def floodFill(self, image, sr, sc, newColor): def dfs(i, j, val, newColor): if i < 0 or i >= rows or j < 0 or j >= cols or image[i][j] != val: return image[i][j] = newColor dfs(i - 1, j, val, newColor) dfs(i + 1, j, val, newCo...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR RETURN ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VA...
Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't). q events are abou...
from sys import stdin input = stdin.readline n, q = list(map(int, input().split())) arr = [tuple(map(int, input().split())) for _ in range(q)] adj = [[] for _ in range(n + 1)] curr, cnt, res, vis = 0, 0, [], [] for t, v in arr: if t == 1: adj[v].append(len(vis)) vis.append(0) cnt += 1 e...
ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER LIST LIST FOR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL V...
Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't). q events are abou...
from sys import stdin input = stdin.readline n, q = map(int, input().split()) is_read_index = 0 is_read = [] l = [[] for i in range(n)] ans = 0 prev = 0 for _ in range(q): t, v = map(int, input().split()) if t == 1: l[v - 1].append(is_read_index) is_read_index += 1 is_read.append(False)...
ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VA...
Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't). q events are abou...
n, q = map(int, input().split()) xi = [([0] * (n + 1)) for i in range(2)] noti = [] ans = "" num = 0 num2 = 0 num3 = 0 while q > 0: typ, xt = map(int, input().split()) if typ == 1: xi[0][xt] += 1 noti += [xt] num += 1 num2 += 1 elif typ == 3: for i in range(num3, xt):...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR...
Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't). q events are abou...
n, q = list(map(int, input().split())) count = [(0) for i in range(n + 1)] queue = [] read = set() unread = 0 ans = [] last_q_idx = 0 last_app_idx = [(1) for i in range(n + 1)] for i in range(q): action, num = list(map(int, input().split())) if action == 1: queue.append((num, count[num] + 1)) co...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CA...