description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
def pathCounts(root): d = {} x = [] def helper(root): q = [] level = 1 if not root: return None q.append(root) while q: count = 0 for i in range(len(q)): a = q.pop(0) if a.left: q...
FUNC_DEF ASSIGN VAR DICT ASSIGN VAR LIST FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER IF VAR RETURN NONE EXPR FUNC_CALL VAR VAR WHILE VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR VAR IF VAR NONE VAR NONE VAR NUMBER IF...
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
def pathCounts(root): paths = {} count = 0 def traverse(root): nonlocal count if root == None: return count += 1 if root.left == root.right == None: if paths.get(count) == None: paths[count] = 1 else: paths[...
FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER FUNC_DEF IF VAR NONE RETURN VAR NUMBER IF VAR VAR NONE IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR STRING EXPR ...
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
def path(dic, root, level): if root: if root.left is None and root.right is None: if level in dic: dic[level] += 1 else: dic[level] = 1 path(dic, root.left, level + 1) path(dic, root.right, level + 1) def pathCounts(root): dic = {...
FUNC_DEF IF VAR IF VAR NONE VAR NONE IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR DICT EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL ...
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
def pathCounts(root): def dfs(root, cnt): if root.left == None and root.right == None: cnt += 1 hm[cnt] = 1 + hm.get(cnt, 0) return cnt += 1 if root.left: dfs(root.left, cnt) if root.right: dfs(root.right, cnt) res = [...
FUNC_DEF FUNC_DEF IF VAR NONE VAR NONE VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR DICT EXPR FUNC_CALL VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL ...
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
def pathCounts(root): d = {} def sol(r, cur): nonlocal d if r == None: return if r.left == None and r.right == None: cur += 1 if cur in d: d[cur] += 1 else: d[cur] = 1 return sol(r.left, ...
FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR NONE RETURN IF VAR NONE VAR NONE VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL V...
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
def height(root): if root is None: return 0 return max(height(root.left), height(root.right)) + 1 def dfs(root, level, path): if root.left is None and root.right is None: path[level] += 1 if root.left: dfs(root.left, level + 1, path) if root.right: dfs(root.right, l...
FUNC_DEF IF VAR NONE RETURN NUMBER RETURN BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR NONE VAR NONE VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUN...
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
def pathCounts(root): if root is None: return "0 0 $" queue = [root] path_lengths = {} length = 1 while queue: n = len(queue) for i in range(len(queue)): node = queue.pop(0) if node.left is None and node.right is None: if length not in ...
FUNC_DEF IF VAR NONE RETURN STRING ASSIGN VAR LIST VAR ASSIGN VAR DICT ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR NONE VAR NONE IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL...
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
def pathCounts(root): l = [] d = {} def helper(root): if root is None: return l.append(root.data) if not root.left and not root.right: if len(l) not in d: d[len(l)] = 0 d[len(l)] += 1 helper(root.left) helper(root.r...
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR DICT FUNC_DEF IF VAR NONE RETURN EXPR FUNC_CALL VAR VAR IF VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR ...
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
def solve(root, ans, level): if root == None: return if root.left == None and root.right == None: ans.append(level) solve(root.left, ans, level + 1) solve(root.right, ans, level + 1) def pathCounts(root): ans = [] solve(root, ans, 1) ans.sort() count = 1 for i in ra...
FUNC_DEF IF VAR NONE RETURN IF VAR NONE VAR NONE EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR ...
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
def dfs(root, curr, hashmap): if not root: return curr += 1 if root.left == None and root.right == None: if curr not in hashmap: hashmap[curr] = 0 hashmap[curr] += 1 return dfs(root.left, curr, hashmap) dfs(root.right, curr, hashmap) def pathCounts(root)...
FUNC_DEF IF VAR RETURN VAR NUMBER IF VAR NONE VAR NONE IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR DICT EXPR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUN...
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
def path(root, count, l): if root == None: return if root.left == None and root.right == None: l.append(count) return path(root.left, count + 1, l) path(root.right, count + 1, l) def pathCounts(root): l = [] count = 1 path(root, count, l) for i in set(l): ...
FUNC_DEF IF VAR NONE RETURN IF VAR NONE VAR NONE EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL V...
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
def fn(root, dic, lvl): if root: if not root.left and not root.right: try: dic[lvl] += 1 except: dic[lvl] = 1 fn(root.left, dic, lvl + 1) fn(root.right, dic, lvl + 1) def pathCounts(root): dic = {} s = "" fn(root, dic, 1) ...
FUNC_DEF IF VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR DICT ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR VA...
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
table = dict() def solve(node, c=0): c += 1 if node == None: return if node.left == None and node.right == None: if c not in table: table[c] = 0 table[c] += 1 return solve(node.left, c) solve(node.right, c) return def pathCounts(root): global t...
ASSIGN VAR FUNC_CALL VAR FUNC_DEF NUMBER VAR NUMBER IF VAR NONE RETURN IF VAR NONE VAR NONE IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR VAR VAR BIN_OP BIN_OP BIN_OP ...
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
def pathCounts(root): dic = dict() def rec(nod, dis): if nod.left is None and nod.right is None: if dis not in dic: dic[dis] = 0 dic[dis] += 1 return if nod.left: rec(nod.left, dis + 1) if nod.right: rec(nod.rig...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR NONE VAR NONE IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER RETURN IF VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR STRING S...
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
def solve(root, lis, count): if root == None: return count += 1 if root.left == None and root.right == None: lis.append(count) solve(root.left, lis, count) solve(root.right, lis, count) count -= 1 def pathCounts(root): lis = [] ans = [] solve(root, lis, 0) ans =...
FUNC_DEF IF VAR NONE RETURN VAR NUMBER IF VAR NONE VAR NONE EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VA...
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
def pathCounts(root): def traversal(root): nonlocal count if root == None: return None count += 1 if root.left == None and root.right == None: if count not in dict1: dict1[count] = 1 else: dict1[count] += 1 ...
FUNC_DEF FUNC_DEF IF VAR NONE RETURN NONE VAR NUMBER IF VAR NONE VAR NONE IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL V...
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
def recur(root, level, d): if not root: return if not root.left and not root.right: if level in d: d[level] += 1 else: d[level] = 1 recur(root.left, level + 1, d) recur(root.right, level + 1, d) def pathCounts(root): d = {} recur(root, 1, d) ...
FUNC_DEF IF VAR RETURN IF VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR DICT EXPR FUNC_CALL VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR STRIN...
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
def pathCounts(root): l = get(root) d = {} for item in l: if item in d: d[item] += 1 else: d[item] = 1 for item in d: print(item, d[item], "$", end="") print() def get(root): if root: if root.left == None and root.right == None: ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR STRING STRING EXPR FUNC_CALL VAR FUNC_DEF IF VAR IF VAR NONE VAR NONE RETURN LIST NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR ...
Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Example 1: Input: 3 / \ 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2(3 -> 2 and 3 -> 4) Example 2: Input: 10 / \ 20 30 / \ 40 60 Out...
def pathCounts(root): temp = 0 global _list1 _list1 = [] if root.left: pathCountsUtil(root.left, temp + 1) if root.right: pathCountsUtil(root.right, temp + 1) s = set() for i in _list1: s.add(i) for i in s: print(str(i) + " " + str(_list1.count(i)) + " $",...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST IF VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR FUNC_CALL VAR VAR STRING STRIN...
Given an array of lowercase strings A[] of size N, determine if the strings can be chained together to form a circle. A string X can be chained together with another string Y if the last character of X is same as first character of Y. If every string of the array can be chained with exactly two strings of the array(one...
def dfs(g, i): global visited visited[i] = True for j in g[i]: if visited[j] == False: dfs(g, j) def Circle(s): global visited n = len(s) mark = [False] * 26 adj = {i: [] for i in range(26)} indegree, outdegree = [0] * 26, [0] * 26 for i in s: u, v = ord...
FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER NUMBER BIN_OP LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CA...
Given an array of lowercase strings A[] of size N, determine if the strings can be chained together to form a circle. A string X can be chained together with another string Y if the last character of X is same as first character of Y. If every string of the array can be chained with exactly two strings of the array(one...
class Solution: def DFS(self, adj, start, visited): visited[start] = 1 for ch in adj[start]: if visited[ch] == 0: self.DFS(adj, ch, visited) def CheckLoop(self, adj, characters, start): visited = [0] * 26 self.DFS(adj, start, visited) for i i...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER A...
Given an array of lowercase strings A[] of size N, determine if the strings can be chained together to form a circle. A string X can be chained together with another string Y if the last character of X is same as first character of Y. If every string of the array can be chained with exactly two strings of the array(one...
class Solution: def isCircle(self, N, A): adj, wcnt, vis, c = {}, {}, set(), 0 for w in A: if w[0] not in adj: adj[w[0]] = [w[-1]] else: adj[w[0]].append(w[-1]) if w[0] not in wcnt: wcnt[w[0]] = 1 else: ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR DICT DICT FUNC_CALL VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER LIST VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER ...
Given an array of lowercase strings A[] of size N, determine if the strings can be chained together to form a circle. A string X can be chained together with another string Y if the last character of X is same as first character of Y. If every string of the array can be chained with exactly two strings of the array(one...
CHARS = 26 class Graph(object): def __init__(self, V): self.V = V self.adj = [[] for x in range(V)] self.inp = [0] * V def addEdge(self, v, w): self.adj[v].append(w) self.inp[w] += 1 def isEulerianCycle(self): if self.isSconnected() == False: ...
ASSIGN VAR NUMBER CLASS_DEF VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FUNC_DEF IF FUNC_CALL VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DE...
Given an array of lowercase strings A[] of size N, determine if the strings can be chained together to form a circle. A string X can be chained together with another string Y if the last character of X is same as first character of Y. If every string of the array can be chained with exactly two strings of the array(one...
class Solution: def isCircle(self, N, A): def dfs(visited, v, adj): visited[v] = True for i in adj[v]: if not visited[i]: dfs(visited, i, adj) def isconnected(adj, mark, v): visited = [False] * 26 dfs(visited, v, ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN...
Given an array of lowercase strings A[] of size N, determine if the strings can be chained together to form a circle. A string X can be chained together with another string Y if the last character of X is same as first character of Y. If every string of the array can be chained with exactly two strings of the array(one...
class Solution: def __init__(self): self.V = 26 self.adj = [[] for x in range(26)] self.inp = [0] * 26 def addEdge(self, v, w): self.adj[v].append(w) self.inp[w] += 1 def isSC(self): visited = [False] * self.V n = 0 for n in range(self.V): ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_DEF EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR ...
Given an array of lowercase strings A[] of size N, determine if the strings can be chained together to form a circle. A string X can be chained together with another string Y if the last character of X is same as first character of Y. If every string of the array can be chained with exactly two strings of the array(one...
import sys class Graph: def __init__(self, v): self.v = v self.adj = [[] for i in range(v)] self.inp = [0] * v def addEdge(self, v, w): self.adj[v].append(w) self.inp[w] += 1 def DFSUtil(self, v, visited): visited[v] = True for i in self.adj[v]: ...
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR...
Given an array of lowercase strings A[] of size N, determine if the strings can be chained together to form a circle. A string X can be chained together with another string Y if the last character of X is same as first character of Y. If every string of the array can be chained with exactly two strings of the array(one...
class Solution: def isCircle(self, N, A): endswith = {} startswith = {} first_pal = set() for string in A: start = string[0] end = string[-1] if start == end: first_pal.add(start) continue startswith[sta...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR FUNC_CALL VAR...
Given an array of lowercase strings A[] of size N, determine if the strings can be chained together to form a circle. A string X can be chained together with another string Y if the last character of X is same as first character of Y. If every string of the array can be chained with exactly two strings of the array(one...
import sys class Solution: def dfs(self, node, adj, vis): vis[node] = True for u in adj[node]: if vis[u] == False: self.dfs(u, adj, vis) def isCircle(self, N, A): adj = [[] for i in range(26)] adjr = [[] for i in range(26)] for i in range(N...
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR...
Given an array of lowercase strings A[] of size N, determine if the strings can be chained together to form a circle. A string X can be chained together with another string Y if the last character of X is same as first character of Y. If every string of the array can be chained with exactly two strings of the array(one...
import sys class Solution: def dfs(self, adj, n, vis): vis[n] = 1 for node in adj[n]: if vis[node] == 0: self.dfs(adj, node, vis) def sc(self, v, adj): vis = [False] * v for n in range(v): if len(adj[n]) > 0: break ...
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER RE...
Given an array of lowercase strings A[] of size N, determine if the strings can be chained together to form a circle. A string X can be chained together with another string Y if the last character of X is same as first character of Y. If every string of the array can be chained with exactly two strings of the array(one...
class Solution: def isCircle(self, N, A): adj = dict() in_out_count = dict() for node in A: fl = node[0] ll = node[-1] if adj.get(fl): adj[fl].append(ll) else: adj[fl] = [ll] if not adj.get(ll): ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR IF FUNC_CALL VAR VAR ASSIGN VAR VAR LIST ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP FUNC_C...
Given an array of lowercase strings A[] of size N, determine if the strings can be chained together to form a circle. A string X can be chained together with another string Y if the last character of X is same as first character of Y. If every string of the array can be chained with exactly two strings of the array(one...
def dfs(node, map1, visited): temp = map1[node] if node in map1 else [] if len(temp) == 0: return visited[node] = 1 for i in temp: if visited[i] == 0: dfs(i, map1, visited) def detectCycle(src, map1, mark): visited = [0] * 26 dfs(src, map1, visited) for i in ran...
FUNC_DEF ASSIGN VAR VAR VAR VAR VAR LIST IF FUNC_CALL VAR VAR NUMBER RETURN ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER RETURN NUMBER RETURN N...
Given an array of lowercase strings A[] of size N, determine if the strings can be chained together to form a circle. A string X can be chained together with another string Y if the last character of X is same as first character of Y. If every string of the array can be chained with exactly two strings of the array(one...
class Solution: def isCircle(self, N, A): adj = [[] for i in range(26)] indeg = [(0) for i in range(26)] for i in A: adj[ord(i[0]) - 97].append(ord(i[-1]) - 97) indeg[ord(i[-1]) - 97] += 1 for i in range(26): if len(adj[i]) != indeg[i]: ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ...
Given an array of lowercase strings A[] of size N, determine if the strings can be chained together to form a circle. A string X can be chained together with another string Y if the last character of X is same as first character of Y. If every string of the array can be chained with exactly two strings of the array(one...
import sys class Solution: def getT(adj): tpg = [[] for i in range(26)] for i in range(26): for j in adj[i]: tpg[j].append(i) return tpg def bfs(adj, visited, i): visited[i] = True for j in adj[i]: if visited[j] == False: ...
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FU...
Given an array of lowercase strings A[] of size N, determine if the strings can be chained together to form a circle. A string X can be chained together with another string Y if the last character of X is same as first character of Y. If every string of the array can be chained with exactly two strings of the array(one...
def dfs(adj, u, vis): vis[u] = 1 for i in adj[u]: if vis[i] == 0: dfs(adj, i, vis) class Solution: def isCircle(self, N, A): adj = [[] for i in range(26)] adj_reverse = [[] for i in range(26)] for s in A: u = ord(s[0]) - ord("a") v = ord...
FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC...
Given an array of lowercase strings A[] of size N, determine if the strings can be chained together to form a circle. A string X can be chained together with another string Y if the last character of X is same as first character of Y. If every string of the array can be chained with exactly two strings of the array(one...
class Solution: def isCircle(self, N, A): start = {} end = {} same_letter = {} for string in A: start_letter, end_letter = string[0], string[-1] if start_letter == end_letter: if start_letter not in same_letter: same_letter...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR RETURN NUMBER...
Given an array of lowercase strings A[] of size N, determine if the strings can be chained together to form a circle. A string X can be chained together with another string Y if the last character of X is same as first character of Y. If every string of the array can be chained with exactly two strings of the array(one...
class Solution: def isCircle(self, N, A): adj = [[] for i in range(26)] isVisited = [False] * 26 vertexSet = set() inDegree = [0] * 26 outDegree = [0] * 26 for str in A: start = ord(str[0]) - 97 end = ord(str[len(str) - 1]) - 97 ve...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR N...
Given an array of lowercase strings A[] of size N, determine if the strings can be chained together to form a circle. A string X can be chained together with another string Y if the last character of X is same as first character of Y. If every string of the array can be chained with exactly two strings of the array(one...
class Solution: def isCircle(self, N, A): a = ord("a") V = 26 graph = [[] for _ in range(V)] inv_graph = [[] for _ in range(V)] for word in A: graph[ord(word[0]) - a].append(ord(word[-1]) - a) inv_graph[ord(word[-1]) - a].append(ord(word[0]) - a) ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL ...
Given an array of lowercase strings A[] of size N, determine if the strings can be chained together to form a circle. A string X can be chained together with another string Y if the last character of X is same as first character of Y. If every string of the array can be chained with exactly two strings of the array(one...
class Solution: def isCircle(self, N, A): graph = dict() for string in A: src = string[0] dest = string[-1] if src in graph: graph[src].append(dest) else: graph[src] = [dest] degrees = dict() for string ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR ...
Given an array of lowercase strings A[] of size N, determine if the strings can be chained together to form a circle. A string X can be chained together with another string Y if the last character of X is same as first character of Y. If every string of the array can be chained with exactly two strings of the array(one...
class Solution: def isCircle(self, N, A): def dfs(node, vis, d): vis[node] = 1 for ele in d[node]: if not vis[ele]: dfs(ele, vis, d) alp = "abcdefghijklmnopqrstuvwxyz" d = {} for i in range(N): if A[i][0] not ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER LIST VAR VAR NUMBER VAR VAR VAR NUMBER LIST VAR VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMB...
Given an array of lowercase strings A[] of size N, determine if the strings can be chained together to form a circle. A string X can be chained together with another string Y if the last character of X is same as first character of Y. If every string of the array can be chained with exactly two strings of the array(one...
import sys class Solution: def isCircle(self, N, A): graph = [[] for k in range(26)] indegree = [0] * 26 for el in A: graph[ord(el[0]) - ord("a")].append(ord(el[-1]) - ord("a")) indegree[ord(el[-1]) - ord("a")] += 1 visited = [False] * 26 trans = [[...
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR STRING VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR STRING NUMBER ASSIGN VAR BIN_...
Given an array of lowercase strings A[] of size N, determine if the strings can be chained together to form a circle. A string X can be chained together with another string Y if the last character of X is same as first character of Y. If every string of the array can be chained with exactly two strings of the array(one...
class Solution: def conn(self, node, adj): ref_ver[node] = True if node in adj: for x in adj[node]: if not ref_ver[x]: self.conn(x, adj) return def isCircle(self, N, A): global ref_ver adj = {} ref_ver = {} ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER IF VAR VAR FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN FUNC_DEF ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER LIST V...
Given an array of lowercase strings A[] of size N, determine if the strings can be chained together to form a circle. A string X can be chained together with another string Y if the last character of X is same as first character of Y. If every string of the array can be chained with exactly two strings of the array(one...
import sys class Solution: def isCircle(self, N, A): adj = [[] for i in range(26)] deg = [0] * 26 diff = 97 dic = {} c = 0 for i in range(N): inx = ord(A[i][0]) - diff if inx not in dic: dic[inx] = 1 c += 1 ...
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_...
Given an array of lowercase strings A[] of size N, determine if the strings can be chained together to form a circle. A string X can be chained together with another string Y if the last character of X is same as first character of Y. If every string of the array can be chained with exactly two strings of the array(one...
class Graph(object): def __init__(self, V): self.V = V self.adj = [[] for x in range(V)] self.inp = [(0) for _ in range(V)] def addEdge(self, v, w): self.adj[v].append(w) self.inp[w] += 1 def isEulerCycle(self): if not self.isSC(): return False ...
CLASS_DEF VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FUNC_DEF IF FUNC_CALL VAR RETURN NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER...
Given an array of lowercase strings A[] of size N, determine if the strings can be chained together to form a circle. A string X can be chained together with another string Y if the last character of X is same as first character of Y. If every string of the array can be chained with exactly two strings of the array(one...
MAX_CHARS = 26 class Solution: def dfs(self, u, adj, visited): visited[u] = True for v in adj[u]: if not visited[v]: self.dfs(v, adj, visited) def is_all_edges_connected(self, src, adj, mark, V): visited = [False] * V self.dfs(src, adj, visited) ...
ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR LIST VAR FUNC_CAL...
Given an array of lowercase strings A[] of size N, determine if the strings can be chained together to form a circle. A string X can be chained together with another string Y if the last character of X is same as first character of Y. If every string of the array can be chained with exactly two strings of the array(one...
class Solution: def kosaraju(self, V, adj): badj = [None] * V for i in adj: badj[i] = list(adj[i]) adj = badj def trans(adj, V): tr = {} for i, val in enumerate(adj): if val: for V in val: ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR IF VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR LIST VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR F...
Given an array of lowercase strings A[] of size N, determine if the strings can be chained together to form a circle. A string X can be chained together with another string Y if the last character of X is same as first character of Y. If every string of the array can be chained with exactly two strings of the array(one...
class Graph: def __init__(self): self.adj = [[] for i in range(26)] self.in_degree = [(0) for i in range(26)] self.out_degree = [(0) for i in range(26)] self.no_vertices = 26 class Solution: def DFS(self, node, adj_lst, visited): visited[node] = True for ch in...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR N...
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, s): for i in range(1, len(s)): mul = int(len(s) / i) if s[0:i] * mul == s: return 1 return 0
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR RETURN NUMBER RETURN NUMBER
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, s): l = len(s) for i in range(1, l // 2 + 1): if l % i == 0: j = l // i x = s[:i] * j if x == s: return 1 return 0
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, s): sub_s = "" for i in range(len(s) - 1): sub_s += s[i] construc_s = sub_s * (len(s) // len(sub_s)) if construc_s == s: return 1 return 0
CLASS_DEF FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, s): def _r(s): lps = [0] le = 0 i = 1 m = len(s) while i < m: if s[i] == s[le]: le += 1 i += 1 lps.append(le) elif le =...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR RETURN VAR NUMBER VAR BIN_OP FUNC_C...
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, s): temp = "" cnt = 0 n = len(s) for i in s: temp += i cnt += 1 l = n // cnt if l > 1 and temp * l == s: return 1 return 0
CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, str1): n = len(str1) flag = 0 for i in range(0, len(str1) // 2): sub = str1[0 : i + 1] l = len(sub) exp = n // l if sub * exp == str1: return 1 return 0
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, s): c = 0 for i in s: n = len(s) a = s[0 : n // 2 - c] if len(a) > 0: x = n // len(a) c += 1 if a * x == s: return 1 else: a...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR RETURN NUMBER ASSIGN VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, s): if len(s) <= 1: return 0 for i in range(len(s) // 2): sub = s[: i + 1] currLen = int(len(s) / len(sub)) if sub * currLen == s: return 1 return 0
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def zalgo(self, s): res = [(0) for i in s] l, r, k = 0, 0, 0 for i in range(1, len(s)): if i > r: l, r = i, i while r < len(s) and s[r] == s[r - l]: r += 1 res[i] = r - l r -= 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR...
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, s): p = "" c = 0 n = len(s) for i in s: p += i c += 1 l = n // c if l > 1 and s == p * l: return 1 return 0 if __name__ == "__main__": T = int(input()) for i in range...
CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR BIN_OP VAR VAR RETURN NUMBER RETURN NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUN...
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, s): for i in range(len(s) // 2): ch = s[0 : i + 1] left = len(s) - (i + 1) if left % len(ch) == 0: repeat = ch * (left // len(ch) + 1) if repeat == s: return 1 return 0
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, s): r = len(s) // 2 if s[:r] == s[r:]: return 1 else: if r != 1: r -= 1 while r > 0: if (len(s) - r) % r != 0: r -= 1 else: t = s[:r...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER IF VAR NUMBER VAR NUMBER WHILE VAR NUMBER IF BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR F...
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, s): if len(s) <= 1: return 0 p = "" c = 0 l = len(s) for i in s: p = p + i c = c + 1 k = l // c if k > 1 and s == p * k: return 1 return 0
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR BIN_OP VAR VAR RETURN NUMBER RETURN NUMBER
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, s): temp = "" ans = "" for i in range(len(s) - 1): temp += s[i] if len(s) % len(temp) == 0 and temp * (len(s) // len(temp)) == s: return 1 return 0
CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, s): n = len(s) for i in range(1, n // 2 + 1): if n % i: continue flag = True for j in range(i, n, i): if s[:i] != s[j : j + i]: flag = False break ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR RETURN NUMBER RETURN NUMBER
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, pat): m = len(pat) lps = [0] * m length = 0 i = 1 while i < m: if pat[i] == pat[length]: length += 1 lps[i] = length i += 1 elif length == 0: lps[i] = 0...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER 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 NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR BI...
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, s): mp = {} n = len(s) temp = "" for i in range(n // 2): temp += s[i] if len(s) % len(temp) == 0: if temp * (len(s) // len(temp)) == s: return 1 return 0 if __name__ == "__main__...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_...
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def computeLPSArray(self, str, M, lps): lps[0] = 0 i = 1 length = 0 while i < M: if str[i] == str[length]: length += 1 lps[i] = length i += 1 elif length != 0: length = lps[length...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER 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 NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL...
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, s): factors = [] string_len = len(s) for i in range(1, len(s)): if string_len % i == 0: factors.append(i) for i in factors: if s[:i] * int(len(s) / i) == s: return 1 return 0
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, s): n = len(s) k = 0 j = 1 while k + j < n: if s[k] == s[k + j]: k += 1 elif s[k] != s[k + j]: j += 1 k = 0 if k > 0 and n % (n - k) == 0: return 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def p(self, s): pi = [(0) for i in range(len(s))] q = 0 for i in range(1, len(s)): while q > 0 and s[q] != s[i]: q = pi[q - 1] if s[i] == s[q]: q += 1 pi[i] = q return pi def isRepeat(self, s): ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR WHILE VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CA...
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, s): l = len(s) factors = [] k = 1 def check_rep(n): l = int(len(s) / n) s2 = "" s3 = "" for i in range(0, n): s2 += s[i] for t in range(0, l): s3 += s2 ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER FOR...
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, A): n = len(A) lps = [0] * n for i in range(1, n): x = lps[i - 1] while A[x] != A[i]: if x == 0: x = -1 break x = lps[x - 1] lps[i] = x + 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBE...
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, s): k = 1 i = 0 if len(s) == 2: if s[i] == s[i + 1]: return 1 while k < len(s): if s[i] == s[k]: i += 1 k += 1 m = k while k < len(s): ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER BIN_OP...
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, s): def check(s, s1): k = len(s1) for i in range(0, len(s), k): s2 = s[i : i + k] if s2 != s1: return False return True sum = 0 for i in s: sum = sum + or...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR...
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, s): p = "" c = 0 d = 0 for j in s: p += j c += 1 d = len(s) // c if d > 1 and s == p * d: return 1 return 0
CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR VAR RETURN NUMBER RETURN NUMBER
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, s): lp = [0] * len(s) lp[0] = 0 leni = 0 i = 1 m = len(s) while i < m: if s[leni] == s[i]: lp[i] = leni + 1 i += 1 leni += 1 elif leni != 0: len...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR NU...
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, S): if len(S) == 1: return 0 else: ans = 0 for i in range(1, len(S) // 2 + 1): p = s[:i] if len(S) % len(p) == 0 and S.count(p) == len(S) // len(p): return 1 return...
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER IF VA...
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, s): n = len(s) a = [] for i in range(1, n // 2 + 1): if n % i == 0: a.append(i) i = len(a) - 1 while i >= 0: j = 0 while (j + 2) * a[i] <= len(s) and s[j * a[i] : (j + 1) * a[i]] == s[ ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR BIN_OP V...
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, s): for i in range(1, len(s) // 2 + 1): if len(s) % i == 0: substring = s[:i] if substring * (len(s) // len(substring)) == s: return 1 return 0
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, s): n = len(s) for i in range(1, n): if n % i == 0 and s[:i] * (n // i) == s: return 1 return 0
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, s): if len(s) <= 1: return 0 else: def rep(sub, s): re = "" n = len(s) // len(sub) re = sub * n if re == s: return True else: ...
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER A...
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
def is_possible(string, pat): if len(string) == 0: return 1 if len(string) < len(pat): return 0 pat_len = len(pat) if string[:pat_len] != pat: return 0 return is_possible(string[pat_len:], pat) class Solution: def isRepeat(self, s): s_len = len(s) for i...
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR RETURN NUMBER RETURN FUNC_CALL VAR VAR VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VA...
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, s): if len(s) <= 1: return 0 else: sub_s = "" len_s = len(s) for i in range(0, int(len_s / 2)): sub_s += s[i] check_s = sub_s * int(len_s / len(sub_s)) if check_s == s:...
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, s): l = len(s) for i in range(l // 2, 0, -1): if l % i == 0: r = l // i st = s[0:i] m = "" while r != 0: m = m + st r = r - 1 if m =...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR STRING WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def calc(self, s): n = len(s) lps = [0] * n for i in range(1, n): j = lps[i - 1] while j > 0 and s[j] != s[i]: j = lps[j - 1] if s[i] == s[j]: j += 1 lps[i] = j return lps def isRepe...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN V...
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, s): M = len(s) lps = [0] * M length = 0 lps[0] = 0 i = 1 while i < M: if s[i] == s[length]: length += 1 lps[i] = length i += 1 elif length != 0: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER 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 NUMBER ASSIGN VAR VAR BIN_OP V...
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, s): for l in range(len(s) // 2, 0, -1): if len(s) % l == 0: i = 0 while i + l < len(s) and s[i] == s[i + l]: i += 1 if l + i == len(s): return 1 return 0
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, s): n = len(s) for i in range(1, n): if n % i == 0: substring = s[:i] new_str = substring while len(new_str) < n: new_str += substring if new_str == s: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, s): r = len(s) // 2 if s[:r] == s[r:]: return 1 else: if r != 1: r -= 1 while r > 0: if (len(s) - r) % r != 0: r -= 1 else: t = s[:r...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER IF VAR NUMBER VAR NUMBER WHILE VAR NUMBER IF BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR F...
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def constructLPS(self, s): n = len(s) lps = [0] * n l = 0 i = 1 while i < n: if s[i] == s[l]: l += 1 lps[i] = l i += 1 elif l != 0: l = lps[l - 1] else: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER 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 ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR...
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, s): cur = s[0] k = len(s) // 2 for i in range(1, k + 1): if cur * (len(s) // i) == s: return 1 else: cur += s[i] return 0
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR VAR RETURN NUMBER VAR VAR VAR RETURN NUMBER
Given a string s, the task is to check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. Example 1: Input: s = "ababab" Output: 1 Explanation: It is contructed by appending "ab" 3 times Example 2: Input: s = "ababac" Output: 0 Explanation: Not possible to c...
class Solution: def isRepeat(self, s): len_s = len(s) if len_s <= 1: return 0 i = len_s // 2 j = 0 while j < i: if s[: j + 1] * (len_s // (j + 1)) == s: return 1 j += 1 return 0 if __name__ == "__main__": T = ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR RETURN NUMBER VAR NUMBER RETURN NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ...
Given an unsorted array arr[ ] of size n, you need to find the maximum difference of absolute values of elements and indexes, i.e., for i <= j, calculate maximum of | arr[ i ] - arr[ j ] | + | i - j |. Example 1: Input : n = 3 arr[ ] = {1, 3, -1} Output: 5 Explanation: Maximum difference comes from indexes 1, 2 i.e ...
import sys class Solution: def maxDistance(self, arr, n): max1 = -sys.maxsize min1 = sys.maxsize max2 = -sys.maxsize min2 = sys.maxsize for i in range(n): max1 = max(max1, arr[i] - i) min1 = min(min1, arr[i] - i) max2 = max(max2, arr[i] ...
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_...
Given an unsorted array arr[ ] of size n, you need to find the maximum difference of absolute values of elements and indexes, i.e., for i <= j, calculate maximum of | arr[ i ] - arr[ j ] | + | i - j |. Example 1: Input : n = 3 arr[ ] = {1, 3, -1} Output: 5 Explanation: Maximum difference comes from indexes 1, 2 i.e ...
class Solution: def maxDistance(self, arr, n): max_diff = 0 min_diff = 0 start_i = 0 for end_i in range(len(arr)): max_diff = max(max_diff, arr[end_i] - arr[start_i] + end_i - start_i) if arr[end_i] - arr[start_i] + end_i - start_i <= 0: start...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUN...
Given an unsorted array arr[ ] of size n, you need to find the maximum difference of absolute values of elements and indexes, i.e., for i <= j, calculate maximum of | arr[ i ] - arr[ j ] | + | i - j |. Example 1: Input : n = 3 arr[ ] = {1, 3, -1} Output: 5 Explanation: Maximum difference comes from indexes 1, 2 i.e ...
class Solution: def maxDistance(self, arr, n): ans = 0 for index1 in range(n): for index2 in range(index1 + 1, n): ans = max(ans, abs(arr[index1] - arr[index2]) + abs(index1 - index2)) return ans def maxDistance(self, arr, n): max1 = -32767 m...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER RETUR...
Given an unsorted array arr[ ] of size n, you need to find the maximum difference of absolute values of elements and indexes, i.e., for i <= j, calculate maximum of | arr[ i ] - arr[ j ] | + | i - j |. Example 1: Input : n = 3 arr[ ] = {1, 3, -1} Output: 5 Explanation: Maximum difference comes from indexes 1, 2 i.e ...
class Solution: def maxDistance(self, arr, n): l = [] m = [] for i in range(n): l.append(arr[i] + i) m.append(arr[i] - i) k = max(l) - min(l) e = max(m) - min(m) return max(k, e)
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR VAR
Given an unsorted array arr[ ] of size n, you need to find the maximum difference of absolute values of elements and indexes, i.e., for i <= j, calculate maximum of | arr[ i ] - arr[ j ] | + | i - j |. Example 1: Input : n = 3 arr[ ] = {1, 3, -1} Output: 5 Explanation: Maximum difference comes from indexes 1, 2 i.e ...
class Solution: def maxDistance(self, arr, n): mx1 = float("-inf") mn1 = float("inf") mx2 = float("-inf") mn2 = float("inf") for i in range(n): mx1 = max(mx1, arr[i] - i) mn1 = min(mn1, arr[i] - i) mx2 = max(mx2, arr[i] + i) mn...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASS...
Given an unsorted array arr[ ] of size n, you need to find the maximum difference of absolute values of elements and indexes, i.e., for i <= j, calculate maximum of | arr[ i ] - arr[ j ] | + | i - j |. Example 1: Input : n = 3 arr[ ] = {1, 3, -1} Output: 5 Explanation: Maximum difference comes from indexes 1, 2 i.e ...
class Solution: def maxDistance(self, A, num): case1Max = caseMax = float("-inf") case2Min = case4Min = float("inf") for i, num in enumerate(A): case1Max = max(case1Max, num + i) case2Min = min(case2Min, num + i) caseMax = max(caseMax, num - i) ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR STRING FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR BI...
Given an unsorted array arr[ ] of size n, you need to find the maximum difference of absolute values of elements and indexes, i.e., for i <= j, calculate maximum of | arr[ i ] - arr[ j ] | + | i - j |. Example 1: Input : n = 3 arr[ ] = {1, 3, -1} Output: 5 Explanation: Maximum difference comes from indexes 1, 2 i.e ...
import sys class Solution: def maxDistance(self, arr, n): min1 = sys.maxsize min2 = sys.maxsize max1 = -sys.maxsize - 1 max2 = -sys.maxsize - 1 if n == 1: return 0 for i in range(n): max1 = max(max1, arr[i] + i) min1 = min(min1, ...
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN V...
Given an unsorted array arr[ ] of size n, you need to find the maximum difference of absolute values of elements and indexes, i.e., for i <= j, calculate maximum of | arr[ i ] - arr[ j ] | + | i - j |. Example 1: Input : n = 3 arr[ ] = {1, 3, -1} Output: 5 Explanation: Maximum difference comes from indexes 1, 2 i.e ...
class Solution: def maxDistance(self, arr, n): n = len(arr) maxi1, maxi2 = -float("inf"), -float("inf") for i in range(n): f_i_1 = arr[i] - i f_i_2 = -arr[i] - i maxi1 = max(maxi1, f_i_1) maxi2 = max(maxi2, f_i_2) maxj1, maxj2 = -float...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING FOR VA...
Given an unsorted array arr[ ] of size n, you need to find the maximum difference of absolute values of elements and indexes, i.e., for i <= j, calculate maximum of | arr[ i ] - arr[ j ] | + | i - j |. Example 1: Input : n = 3 arr[ ] = {1, 3, -1} Output: 5 Explanation: Maximum difference comes from indexes 1, 2 i.e ...
class Solution: def maxDistance(self, arr, n): p = [] s = [] for i in range(n): k = arr[i] - i d = arr[i] + i s.append(k) p.append(d) p.sort() s.sort() x1 = p[len(p) - 1] - p[0] x2 = s[len(s) - 1] - s[0] ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP FUNC_...
Given an unsorted array arr[ ] of size n, you need to find the maximum difference of absolute values of elements and indexes, i.e., for i <= j, calculate maximum of | arr[ i ] - arr[ j ] | + | i - j |. Example 1: Input : n = 3 arr[ ] = {1, 3, -1} Output: 5 Explanation: Maximum difference comes from indexes 1, 2 i.e ...
class Solution: def maxDistance(self, arr, n): r0 = arr[0] rn = arr[n - 1] v0p = v0m = vnp = vnm = 0 i0p = i0m = 0 inp = inm = n - 1 for i in range(n): if arr[i] - r0 - i > v0p: v0p = arr[i] - r0 - i i0p = i if ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIG...
Given an unsorted array arr[ ] of size n, you need to find the maximum difference of absolute values of elements and indexes, i.e., for i <= j, calculate maximum of | arr[ i ] - arr[ j ] | + | i - j |. Example 1: Input : n = 3 arr[ ] = {1, 3, -1} Output: 5 Explanation: Maximum difference comes from indexes 1, 2 i.e ...
class Solution: def maxDistance(self, arr, n): while len(arr) > 1: max1 = -2147483648 max2 = -2147483648 min1 = arr[0] + 0 min2 = arr[0] - 0 sum = 0 diff = 0 for i in range(n): sum = arr[i] + i ...
CLASS_DEF FUNC_DEF WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP ...