description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K.
Note: Coins of the negative denomination are also possible at Geekland.
Example 1:
Input: N = 5, K = 3
mat[[]] = {1, 1, 1, 1, 1}
{2, 2, 2, 2, 2}
{3, 8, 6, 7, 3}
... | class Solution:
def Maximum_Sum(self, mat, N, K):
col_sum = [([0] * N) for i in range(N)]
for j in range(N):
for i in range(K):
col_sum[i][j] = mat[i][j] + (col_sum[i - 1][j] if i > 0 else 0)
for j in range(N):
for i in range(K, N):
co... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP... |
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K.
Note: Coins of the negative denomination are also possible at Geekland.
Example 1:
Input: N = 5, K = 3
mat[[]] = {1, 1, 1, 1, 1}
{2, 2, 2, 2, 2}
{3, 8, 6, 7, 3}
... | class Solution:
def Maximum_Sum(self, mat, N, K):
dp = [([0] * (N + 1)) for i in range(N + 1)]
for i in range(1, N + 1):
for j in range(1, N + 1):
if i == 1:
dp[i][j] = dp[i][j - 1] + mat[i - 1][j - 1]
elif j == 1:
... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASS... |
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K.
Note: Coins of the negative denomination are also possible at Geekland.
Example 1:
Input: N = 5, K = 3
mat[[]] = {1, 1, 1, 1, 1}
{2, 2, 2, 2, 2}
{3, 8, 6, 7, 3}
... | class Solution:
def Maximum_Sum(self, mat, N, K):
prefixsum = [[(0) for i in range(N)] for m in mat]
prefixsum[0][0] = mat[0][0]
for r in range(N):
currentrow = 0
for c in range(N):
currentrow += mat[r][c]
prefixsum[r][c] = currentrow ... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_DEF IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR ... |
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K.
Note: Coins of the negative denomination are also possible at Geekland.
Example 1:
Input: N = 5, K = 3
mat[[]] = {1, 1, 1, 1, 1}
{2, 2, 2, 2, 2}
{3, 8, 6, 7, 3}
... | import sys
class Solution:
def Maximum_Sum(self, mat, N, K):
dp = [([0] * (N + 1)) for _ in range(N + 1)]
for i in range(1, N + 1):
for j in range(1, N + 1):
dp[i][j] = (
mat[i - 1][j - 1] + dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]
... | IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR BI... |
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K.
Note: Coins of the negative denomination are also possible at Geekland.
Example 1:
Input: N = 5, K = 3
mat[[]] = {1, 1, 1, 1, 1}
{2, 2, 2, 2, 2}
{3, 8, 6, 7, 3}
... | class Solution:
def Maximum_Sum(self, mat, n, k):
dp = [[(-1000000) for i in range(n)] for j in range(n)]
sm = 0
for i in range(n):
sm = 0
for j in range(n):
if j < k:
sm = sm + mat[i][j]
if j == k - 1:
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VA... |
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K.
Note: Coins of the negative denomination are also possible at Geekland.
Example 1:
Input: N = 5, K = 3
mat[[]] = {1, 1, 1, 1, 1}
{2, 2, 2, 2, 2}
{3, 8, 6, 7, 3}
... | class Solution:
def Maximum_Sum(self, mat, N, K):
ps = [[(0) for _ in range(N)] for _ in range(N)]
s = s2 = 0
for i in range(N):
s += mat[i][0]
s2 += mat[0][i]
ps[i][0] = s
ps[0][i] = s2
for i in range(1, N):
for j in range... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP BI... |
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K.
Note: Coins of the negative denomination are also possible at Geekland.
Example 1:
Input: N = 5, K = 3
mat[[]] = {1, 1, 1, 1, 1}
{2, 2, 2, 2, 2}
{3, 8, 6, 7, 3}
... | class Solution:
def Maximum_Sum(self, mat, N, K):
temp = [[(-1) for i in range(0, N)] for i in range(0, N)]
for ind in range(0, N):
i, j = 0, 0
summ = 0
while j < n:
summ += mat[ind][j]
if j - i + 1 == K:
temp[i... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CA... |
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K.
Note: Coins of the negative denomination are also possible at Geekland.
Example 1:
Input: N = 5, K = 3
mat[[]] = {1, 1, 1, 1, 1}
{2, 2, 2, 2, 2}
{3, 8, 6, 7, 3}
... | class Solution:
def Maximum_Sum(self, mat, N, K):
arr = mat
n = N
k = K
dp = [([0] * n) for i in range(n)]
for i in range(n):
for j in range(n):
if i == 0:
dp[i][j] = arr[i][j]
elif i - k >= 0:
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN... |
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K.
Note: Coins of the negative denomination are also possible at Geekland.
Example 1:
Input: N = 5, K = 3
mat[[]] = {1, 1, 1, 1, 1}
{2, 2, 2, 2, 2}
{3, 8, 6, 7, 3}
... | class Solution:
def Maximum_Sum(self, mat, N, K):
start = 0
for i in range(K):
for j in range(K):
start += mat[i][j]
dp = [[(0) for j in range(N)] for i in range(N)]
dp[K - 1][K - 1] = start
rowSum = [[y for y in x] for x in mat]
colSum = ... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_C... |
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K.
Note: Coins of the negative denomination are also possible at Geekland.
Example 1:
Input: N = 5, K = 3
mat[[]] = {1, 1, 1, 1, 1}
{2, 2, 2, 2, 2}
{3, 8, 6, 7, 3}
... | class Solution:
def Maximum_Sum(self, mat, N, K):
prefix = [[(0) for i in range(N)] for j in range(N)]
prefix[0][0] = mat[0][0]
for i in range(1, N):
prefix[0][i] += prefix[0][i - 1] + mat[0][i]
prefix[i][0] += mat[i][0] + prefix[i - 1][0]
m = -1
for ... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_... |
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K.
Note: Coins of the negative denomination are also possible at Geekland.
Example 1:
Input: N = 5, K = 3
mat[[]] = {1, 1, 1, 1, 1}
{2, 2, 2, 2, 2}
{3, 8, 6, 7, 3}
... | import sys
class Solution:
def getSum(self, mat, n):
for i in range(n):
for j in range(n):
top, left, daigonal = 0, 0, 0
if i - 1 >= 0:
top = mat[i - 1][j]
if j - 1 >= 0:
left = mat[i][j - 1]
... | IMPORT CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_... |
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K.
Note: Coins of the negative denomination are also possible at Geekland.
Example 1:
Input: N = 5, K = 3
mat[[]] = {1, 1, 1, 1, 1}
{2, 2, 2, 2, 2}
{3, 8, 6, 7, 3}
... | class Solution:
def Maximum_Sum(self, mat, N, K):
for i in range(1, N):
mat[0][i] += mat[0][i - 1]
mat[i][0] += mat[i - 1][0]
for i in range(1, N):
for j in range(1, N):
mat[i][j] += mat[i - 1][j] + mat[i][j - 1] - mat[i - 1][j - 1]
maxi =... | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUM... |
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K.
Note: Coins of the negative denomination are also possible at Geekland.
Example 1:
Input: N = 5, K = 3
mat[[]] = {1, 1, 1, 1, 1}
{2, 2, 2, 2, 2}
{3, 8, 6, 7, 3}
... | class Solution:
def Maximum_Sum(self, mat, N, K):
pref = mat.copy()
for i in range(1, N):
pref[0][i] += pref[0][i - 1]
pref[i][0] += pref[i - 1][0]
for i in range(1, N):
for j in range(1, N):
pref[i][j] += pref[i - 1][j] + pref[i][j - 1] -... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP ... |
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K.
Note: Coins of the negative denomination are also possible at Geekland.
Example 1:
Input: N = 5, K = 3
mat[[]] = {1, 1, 1, 1, 1}
{2, 2, 2, 2, 2}
{3, 8, 6, 7, 3}
... | class Solution:
def Maximum_Sum(self, mat, N, K):
for i in range(1, N):
for j in range(N):
mat[i][j] += mat[i - 1][j]
ans = -(2**63) + 1
dp = [([0] * N) for i in range(N)]
start = 0
for i in range(K):
for j in range(N):
... | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR F... |
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K.
Note: Coins of the negative denomination are also possible at Geekland.
Example 1:
Input: N = 5, K = 3
mat[[]] = {1, 1, 1, 1, 1}
{2, 2, 2, 2, 2}
{3, 8, 6, 7, 3}
... | class Solution:
def Maximum_Sum(self, mat, N, K):
for i in range(N):
for j in range(1, N):
mat[i][j] += mat[i][j - 1]
for i in range(1, N):
for j in range(N):
mat[i][j] += mat[i - 1][j]
ans = 0
for i in range(K - 1, N):
... | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR A... |
In Geekland there is a grid of coins of size N x N. You have to find the maximum sum of coins in any sub-grid of size K x K.
Note: Coins of the negative denomination are also possible at Geekland.
Example 1:
Input: N = 5, K = 3
mat[[]] = {1, 1, 1, 1, 1}
{2, 2, 2, 2, 2}
{3, 8, 6, 7, 3}
... | class Solution:
def Maximum_Sum(self, mat, N, k):
dp = [[(0) for _ in range(N)] for _ in range(N)]
for i in range(N):
for j in range(N):
if i == 0 and j == 0:
dp[i][j] = mat[i][j]
elif i == 0:
dp[i][j] = mat[i][j] +... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR V... |
The Romans have attacked again. This time they are much more than the Persians but Shapur is ready to defeat them. He says: "A lion is never afraid of a hundred sheep".
Nevertheless Shapur has to find weaknesses in the Roman army to defeat them. So he gives the army a weakness number.
In Shapur's opinion the weaknes... | def update(bit, i):
while i < len(bit):
bit[i] += 1
i += i & -i
def getsum(bit, i):
res = 0
while i > 0:
res += bit[i]
i -= i & -i
return res
n = int(input())
arr = list(map(int, input().split()))
l = sorted(arr)
d = {}
ind = 1
for i in range(n):
if not d.get(l[i]... | FUNC_DEF WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR RETURN 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 VAR ASSIGN VAR DICT ASSIGN VAR N... |
The Romans have attacked again. This time they are much more than the Persians but Shapur is ready to defeat them. He says: "A lion is never afraid of a hundred sheep".
Nevertheless Shapur has to find weaknesses in the Roman army to defeat them. So he gives the army a weakness number.
In Shapur's opinion the weaknes... | def and_i(i):
return i & i + 1
def or_i(i):
return i | i + 1
class Tree:
def __init__(self, n):
self.n = n
self.tree = [0] * n
def get_sum(self, i):
ans = 0
while i >= 0:
ans += self.tree[i]
i = and_i(i) - 1
return ans
def update... | FUNC_DEF RETURN BIN_OP VAR BIN_OP VAR NUMBER FUNC_DEF RETURN BIN_OP VAR BIN_OP VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN VAR FUNC_DEF NUMBER WHILE VAR VAR VAR VAR VAR ASSIGN VAR... |
The Romans have attacked again. This time they are much more than the Persians but Shapur is ready to defeat them. He says: "A lion is never afraid of a hundred sheep".
Nevertheless Shapur has to find weaknesses in the Roman army to defeat them. So he gives the army a weakness number.
In Shapur's opinion the weaknes... | from sys import stdin, stdout
def binarysearch(x, first, last, b):
mid = (first + last) / 2
mid = int(mid)
if b[first] == x:
return first
if b[last] == x:
return last
if b[mid] == x:
return mid
if b[mid] < x:
return binarysearch(x, mid, last, b)
return binar... | FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR RETURN VAR IF VAR VAR VAR RETURN VAR IF VAR VAR VAR RETURN VAR IF VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER EXPR FUNC_CAL... |
The Romans have attacked again. This time they are much more than the Persians but Shapur is ready to defeat them. He says: "A lion is never afraid of a hundred sheep".
Nevertheless Shapur has to find weaknesses in the Roman army to defeat them. So he gives the army a weakness number.
In Shapur's opinion the weaknes... | from sys import stdin, stdout
def getSum(BiTree, i, n):
sum = 0
while i > 0:
sum += BiTree[i]
i -= i & -i
return sum
def update(BiTree, i, n, val):
while i < n:
BiTree[i] += val
i += i & -i
def construct(a, BiTree, a2, a3, n):
lcount = [(0) for i in range(n)]
... | FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF WHILE VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR NUMB... |
The Romans have attacked again. This time they are much more than the Persians but Shapur is ready to defeat them. He says: "A lion is never afraid of a hundred sheep".
Nevertheless Shapur has to find weaknesses in the Roman army to defeat them. So he gives the army a weakness number.
In Shapur's opinion the weaknes... | class Tree:
def __init__(self, n):
self.n = n
self.tree = [0] * n
def fenwick(self, i):
return i & i + 1
def get(self, r):
ans = 0
while r >= 0:
ans += self.tree[r]
r = self.fenwick(r) - 1
return ans
def get2(self, l, r):
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF RETURN BIN_OP VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF RETURN BIN_OP V... |
The Romans have attacked again. This time they are much more than the Persians but Shapur is ready to defeat them. He says: "A lion is never afraid of a hundred sheep".
Nevertheless Shapur has to find weaknesses in the Roman army to defeat them. So he gives the army a weakness number.
In Shapur's opinion the weaknes... | def update(bit, i):
while i < len(bit):
bit[i] += 1
i += i & -i
def getsum(bit, i):
res = 0
while i > 0:
res += bit[i]
i -= i & -i
return res
n = int(input())
arr = list(map(int, input().split()))
d = {}
l = list(sorted(set(arr)))
ind = 1
for i in range(len(l)):
d... | FUNC_DEF WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR RETURN 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 DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FU... |
Given a Binary tree, the problem is to find mirror of a given node. The mirror of a node is a node which exist at the mirror position of node in opposite subtree at the root.
Example 1:
Input:
1
/ \
2 3
/ \ / \
4 5 6 7
and target = 4
Output: 7
... | class Solution:
def mirrorTree(self, root1, root2):
if root1 is None:
return
if root1.data == target:
self.mirrorNode = root2.data
if root1.right:
root2.left = Node(root1.right.data)
self.mirrorTree(root1.right, root2.left)
if root1.le... | CLASS_DEF FUNC_DEF IF VAR NONE RETURN IF VAR VAR ASSIGN VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR NONE VAR NONE RETURN IF VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR F... |
Given a Binary tree, the problem is to find mirror of a given node. The mirror of a node is a node which exist at the mirror position of node in opposite subtree at the root.
Example 1:
Input:
1
/ \
2 3
/ \ / \
4 5 6 7
and target = 4
Output: 7
... | class Solution:
def findMirror(self, root, target):
if root and root.data == target:
return target
if not root:
return -1
global k
k = -1
def sol(root1, root2):
global k
if root1 and root2:
if root1.data == tar... | CLASS_DEF FUNC_DEF IF VAR VAR VAR RETURN VAR IF VAR RETURN NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR IF VAR VAR IF VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR IF VAR ASSIGN VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN VAR RETURN N... |
Given a Binary tree, the problem is to find mirror of a given node. The mirror of a node is a node which exist at the mirror position of node in opposite subtree at the root.
Example 1:
Input:
1
/ \
2 3
/ \ / \
4 5 6 7
and target = 4
Output: 7
... | class Solution:
def findMirror(self, root, target):
q1 = [root]
q2 = [root]
while len(q1) and len(q2):
n = min(len(q1), len(q2))
queue1 = []
queue2 = []
for i in range(n):
node1, node2 = q1[i], q2[i]
if node1 is... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST VAR ASSIGN VAR LIST VAR WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR NONE VAR NONE IF VAR VAR RETURN VAR EXPR FUNC_CALL VAR VAR EXP... |
Given a Binary tree, the problem is to find mirror of a given node. The mirror of a node is a node which exist at the mirror position of node in opposite subtree at the root.
Example 1:
Input:
1
/ \
2 3
/ \ / \
4 5 6 7
and target = 4
Output: 7
... | class Solution:
def findMirror(self, root, target):
if not root:
return -1
arr = []
if root.data == target:
return target
self.findMirrorUtil(root.left, target, arr, [-1])
self.findMirrorUtil(root.right, target, arr, [1])
head = root
f... | CLASS_DEF FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR LIST IF VAR VAR RETURN VAR EXPR FUNC_CALL VAR VAR VAR VAR LIST NUMBER EXPR FUNC_CALL VAR VAR VAR VAR LIST NUMBER ASSIGN VAR VAR FOR VAR VAR IF VAR NUMBER VAR ASSIGN VAR VAR IF VAR NUMBER VAR ASSIGN VAR VAR RETURN NUMBER RETURN VAR FUNC_DEF IF VAR RETURN IF VAR VAR EXPR... |
Given a Binary tree, the problem is to find mirror of a given node. The mirror of a node is a node which exist at the mirror position of node in opposite subtree at the root.
Example 1:
Input:
1
/ \
2 3
/ \ / \
4 5 6 7
and target = 4
Output: 7
... | class Solution:
def findMirror(self, root, target):
if root is None:
return None
def search(root, target, path):
if root is None:
return False, []
newPath = path.copy()
newPath.append(root)
if root.data == target:
... | CLASS_DEF FUNC_DEF IF VAR NONE RETURN NONE FUNC_DEF IF VAR NONE RETURN NUMBER LIST ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR RETURN NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR RETURN NUMBER VAR RETURN NUMBER LIST ASSIGN VA... |
Given a Binary tree, the problem is to find mirror of a given node. The mirror of a node is a node which exist at the mirror position of node in opposite subtree at the root.
Example 1:
Input:
1
/ \
2 3
/ \ / \
4 5 6 7
and target = 4
Output: 7
... | class Solution:
def asd(self, x, y, target, a):
if x == None or y == None:
return
else:
if x.data == target:
a.append(y.data)
self.asd(x.left, y.right, target, a)
self.asd(x.right, y.left, target, a)
def findMirror(self, root, tar... | CLASS_DEF FUNC_DEF IF VAR NONE VAR NONE RETURN IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR VAR IF VAR LIST RETURN NUMBER RETURN VAR NUMBER |
Given a Binary tree, the problem is to find mirror of a given node. The mirror of a node is a node which exist at the mirror position of node in opposite subtree at the root.
Example 1:
Input:
1
/ \
2 3
/ \ / \
4 5 6 7
and target = 4
Output: 7
... | class Solution:
def findMoves(self, node, target):
if node.data == target:
return [0]
left_moves = right_moves = None
if node.left:
left_moves = self.findMoves(node.left, target)
if node.right:
right_moves = self.findMoves(node.right, target)
... | CLASS_DEF FUNC_DEF IF VAR VAR RETURN LIST NUMBER ASSIGN VAR VAR NONE IF VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR RETURN BIN_OP LIST NUMBER VAR IF VAR RETURN BIN_OP LIST NUMBER VAR RETURN NONE FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FOR VAR VAR NUMBER IF VAR NU... |
Given a Binary tree, the problem is to find mirror of a given node. The mirror of a node is a node which exist at the mirror position of node in opposite subtree at the root.
Example 1:
Input:
1
/ \
2 3
/ \ / \
4 5 6 7
and target = 4
Output: 7
... | class Solution:
def helper(self, root):
if root == None:
return
newRoot = Node(root.data)
newRoot.left = self.helper(root.right)
newRoot.right = self.helper(root.left)
return newRoot
def check(self, root, newRoot, k):
if root == None or newRoot == No... | CLASS_DEF FUNC_DEF IF VAR NONE RETURN ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF IF VAR NONE VAR NONE RETURN NUMBER IF VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER RETURN VAR IF VAR NUMBER RETUR... |
Given a Binary tree, the problem is to find mirror of a given node. The mirror of a node is a node which exist at the mirror position of node in opposite subtree at the root.
Example 1:
Input:
1
/ \
2 3
/ \ / \
4 5 6 7
and target = 4
Output: 7
... | class Solution:
def findMirror(self, root, target):
if not root:
return -1
if root.data == target:
return target
mirror = [None]
self._findMirror(root.left, root.right, target, mirror)
return mirror[0] if mirror[0] else -1
def _findMirror(self, l... | CLASS_DEF FUNC_DEF IF VAR RETURN NUMBER IF VAR VAR RETURN VAR ASSIGN VAR LIST NONE EXPR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR NUMBER VAR NUMBER NUMBER FUNC_DEF IF VAR VAR RETURN IF VAR VAR ASSIGN VAR NUMBER VAR RETURN IF VAR VAR ASSIGN VAR NUMBER VAR RETURN EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR V... |
Given a Binary tree, the problem is to find mirror of a given node. The mirror of a node is a node which exist at the mirror position of node in opposite subtree at the root.
Example 1:
Input:
1
/ \
2 3
/ \ / \
4 5 6 7
and target = 4
Output: 7
... | class Solution:
ans = -1
def findMirror(self, root, target):
if root.data == target:
return root.data
if root is None:
return -1
else:
self.isMirror(root.left, root.right, target)
return self.ans
def isMirror(self, left, right, target... | CLASS_DEF ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR RETURN VAR IF VAR NONE RETURN NUMBER EXPR FUNC_CALL VAR VAR VAR VAR RETURN VAR FUNC_DEF IF VAR NONE VAR NONE RETURN IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR |
Given a Binary tree, the problem is to find mirror of a given node. The mirror of a node is a node which exist at the mirror position of node in opposite subtree at the root.
Example 1:
Input:
1
/ \
2 3
/ \ / \
4 5 6 7
and target = 4
Output: 7
... | class Solution:
def checkMirror(self, left, right):
if not left or not right:
return 0
if left.data == target:
return right.data
if right.data == target:
return left.data
else:
return self.checkMirror(left.left, right.right) + self.che... | CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR RETURN VAR IF VAR VAR RETURN VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR RETURN NUMBER RETURN VAR |
Given a Binary tree, the problem is to find mirror of a given node. The mirror of a node is a node which exist at the mirror position of node in opposite subtree at the root.
Example 1:
Input:
1
/ \
2 3
/ \ / \
4 5 6 7
and target = 4
Output: 7
... | class Solution:
def findMirror(self, root, target):
if root.data == target:
return target
kkkk = self.mirror(root.left, root.right, target)
if kkkk:
return kkkk
return -1
def mirror(self, a, b, target):
if a and b:
if a.data == target... | CLASS_DEF FUNC_DEF IF VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR RETURN VAR RETURN NUMBER FUNC_DEF IF VAR VAR IF VAR VAR RETURN VAR IF VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR RETURN VAR RETURN FUNC_CALL VAR VAR VAR VAR |
Given a Binary tree, the problem is to find mirror of a given node. The mirror of a node is a node which exist at the mirror position of node in opposite subtree at the root.
Example 1:
Input:
1
/ \
2 3
/ \ / \
4 5 6 7
and target = 4
Output: 7
... | class Solution:
def soln(self, node1, node2, target, m):
if node1 is None or node2 is None:
return
if node1.data == target:
self.m = node2.data
return
if node2.data == target:
self.m = node1.data
return
l = self.soln(node1.... | CLASS_DEF FUNC_DEF IF VAR NONE VAR NONE RETURN IF VAR VAR ASSIGN VAR VAR RETURN IF VAR VAR ASSIGN VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER RETURN RETURN FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF IF VAR NONE RETURN NUMBER IF VAR VAR RETURN VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VA... |
Given a Binary tree, the problem is to find mirror of a given node. The mirror of a node is a node which exist at the mirror position of node in opposite subtree at the root.
Example 1:
Input:
1
/ \
2 3
/ \ / \
4 5 6 7
and target = 4
Output: 7
... | class Solution:
def findMirror(self, root, target):
path = self.findPath(root, target, [])
for item in path:
if item == "left":
root = root.right
else:
root = root.left
if root is None:
return -1
return root... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR LIST FOR VAR VAR IF VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NONE RETURN NUMBER RETURN VAR FUNC_DEF IF VAR NONE RETURN LIST IF VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR LIST STRING ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL... |
Given a Binary tree, the problem is to find mirror of a given node. The mirror of a node is a node which exist at the mirror position of node in opposite subtree at the root.
Example 1:
Input:
1
/ \
2 3
/ \ / \
4 5 6 7
and target = 4
Output: 7
... | class Solution:
def recur(self, r1, r2, target):
global ans
if not r1 or not r2:
return
if r1.data == target:
ans = r2.data
return
elif r2.data == target:
ans = r1.data
return
self.recur(r1.left, r2.right, target)
... | CLASS_DEF FUNC_DEF IF VAR VAR RETURN IF VAR VAR ASSIGN VAR VAR RETURN IF VAR VAR ASSIGN VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF IF VAR VAR RETURN VAR ASSIGN VAR NONE EXPR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR NUMBER |
Given a Binary tree, the problem is to find mirror of a given node. The mirror of a node is a node which exist at the mirror position of node in opposite subtree at the root.
Example 1:
Input:
1
/ \
2 3
/ \ / \
4 5 6 7
and target = 4
Output: 7
... | class Solution:
def recur(self, r1, r2, t):
global ans
if not r1 or not r2:
return
if r1.data == t:
if r2:
ans = r2.data
if r1.left and r2.right:
self.recur(r1.left, r2.right, t)
if r1.right and r2.left:
self.re... | CLASS_DEF FUNC_DEF IF VAR VAR RETURN IF VAR VAR IF VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR RETURN VAR |
Given a Binary tree, the problem is to find mirror of a given node. The mirror of a node is a node which exist at the mirror position of node in opposite subtree at the root.
Example 1:
Input:
1
/ \
2 3
/ \ / \
4 5 6 7
and target = 4
Output: 7
... | class Solution:
def Mirror(self, root1, root2, target, ans):
if root1 == None and root2 == None:
return
if root1 == None or root2 == None:
return
if root1.data == target:
ans[0] = root2.data
return
self.Mirror(root1.left, root2.right, ... | CLASS_DEF FUNC_DEF IF VAR NONE VAR NONE RETURN IF VAR NONE VAR NONE RETURN IF VAR VAR ASSIGN VAR NUMBER VAR RETURN EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR NUMBER |
Given a Binary tree, the problem is to find mirror of a given node. The mirror of a node is a node which exist at the mirror position of node in opposite subtree at the root.
Example 1:
Input:
1
/ \
2 3
/ \ / \
4 5 6 7
and target = 4
Output: 7
... | class Solution:
def findMirror(self, root, target):
if not root:
return -1
if target == root.data:
return root.data
self.mirror = -1
self.helper(root.left, root.right, target)
return self.mirror
def helper(self, root1, root2, target):
if ... | CLASS_DEF FUNC_DEF IF VAR RETURN NUMBER IF VAR VAR RETURN VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR RETURN VAR FUNC_DEF IF VAR NONE VAR NONE RETURN NONE IF VAR NONE VAR NONE IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NONE IF VAR VAR ASSIGN VAR NUMBER RETURN IF VAR NONE IF VAR VAR ASSIGN VAR N... |
Given a Binary tree, the problem is to find mirror of a given node. The mirror of a node is a node which exist at the mirror position of node in opposite subtree at the root.
Example 1:
Input:
1
/ \
2 3
/ \ / \
4 5 6 7
and target = 4
Output: 7
... | class Solution:
def solve(self, a, b, target):
if not a or not b:
return -1
self.dic[a.data] = b.data
self.dic[b.data] = a.data
self.solve(a.left, b.right, target)
self.solve(a.right, b.left, target)
def findMirror(self, root, target):
self.dic = {}
... | CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR DICT ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN VAR VAR |
Given a Binary tree, the problem is to find mirror of a given node. The mirror of a node is a node which exist at the mirror position of node in opposite subtree at the root.
Example 1:
Input:
1
/ \
2 3
/ \ / \
4 5 6 7
and target = 4
Output: 7
... | class Solution:
def findMirror(self, root, target):
def trav(root, p, k):
if root is None:
return 0
if root.data == p:
return 1
y = trav(root.left, p, k)
if y == 1:
k.append(1)
return 1
... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NONE RETURN NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR VA... |
Given a Binary tree, the problem is to find mirror of a given node. The mirror of a node is a node which exist at the mirror position of node in opposite subtree at the root.
Example 1:
Input:
1
/ \
2 3
/ \ / \
4 5 6 7
and target = 4
Output: 7
... | class Solution:
def findMirror(self, root, target):
directions = []
get_directions(root, target, [], directions)
return find_node(root, directions[0], 0)
def get_directions(cur, target, path, res):
if not cur:
return
if cur.data == target:
res.append("".join(path))... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR LIST VAR RETURN FUNC_CALL VAR VAR VAR NUMBER NUMBER FUNC_DEF IF VAR RETURN IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ... |
Geek has developed an effective vaccine for Corona virus and he wants each of the N houses in Geek Land to have access to it. Given a binary tree where each node represents a house in Geek Land, find the minimum number of houses that should be supplied with the vaccine kit if one vaccine kit is sufficient for that hous... | class Solution:
def supplyVaccine(self, root):
global nv
nv = 0
if self.vacc(root) == 1:
nv += 1
return nv
def vacc(self, root):
global nv
l, r = 0, 0
if root is None:
return 0
l = self.vacc(root.left)
r = self.vac... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER IF VAR NONE RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER |
Geek has developed an effective vaccine for Corona virus and he wants each of the N houses in Geek Land to have access to it. Given a binary tree where each node represents a house in Geek Land, find the minimum number of houses that should be supplied with the vaccine kit if one vaccine kit is sufficient for that hous... | class Solution:
def supplyVaccine(self, root):
cnt = []
def solve(root):
if root == None:
return 1
lChild = solve(root.left)
rChild = solve(root.right)
if lChild == -1 or rChild == -1:
cnt.append(1)
ret... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF VAR NONE RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN FUNC_CALL VAR... |
Geek has developed an effective vaccine for Corona virus and he wants each of the N houses in Geek Land to have access to it. Given a binary tree where each node represents a house in Geek Land, find the minimum number of houses that should be supplied with the vaccine kit if one vaccine kit is sufficient for that hous... | class Solution:
def res(self, root, c):
if root is None:
return 0
l = self.res(root.left, c)
r = self.res(root.right, c)
if l == 0 and r == 1:
return 0
if l == 1 and r == 0:
return 0
if l == 0 and r == 0:
return -1
... | CLASS_DEF FUNC_DEF IF VAR NONE RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER NUMBER RETURN NUM... |
Geek has developed an effective vaccine for Corona virus and he wants each of the N houses in Geek Land to have access to it. Given a binary tree where each node represents a house in Geek Land, find the minimum number of houses that should be supplied with the vaccine kit if one vaccine kit is sufficient for that hous... | class Node:
def _init_(self, val):
self.data = val
self.left = None
self.right = None
class Solution:
v = 0
def solve(self, node):
if node == None:
return 0
l = self.solve(node.left)
r = self.solve(node.right)
if l == 1 or r == 1:
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE CLASS_DEF ASSIGN VAR NUMBER FUNC_DEF IF VAR NONE RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER RETURN BIN_OP BIN_OP VAR NUMBE... |
Geek has developed an effective vaccine for Corona virus and he wants each of the N houses in Geek Land to have access to it. Given a binary tree where each node represents a house in Geek Land, find the minimum number of houses that should be supplied with the vaccine kit if one vaccine kit is sufficient for that hous... | class Solution:
vaccine = 0
def countVaccine(self, root):
if not root:
return "ok"
left = self.countVaccine(root.left)
right = self.countVaccine(root.right)
if left == "want" or right == "want":
self.vaccine += 1
return "provide"
if le... | CLASS_DEF ASSIGN VAR NUMBER FUNC_DEF IF VAR RETURN STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR STRING VAR NUMBER RETURN STRING IF VAR STRING VAR STRING RETURN STRING RETURN STRING FUNC_DEF IF FUNC_CALL VAR VAR STRING VAR NUMBER RETURN VAR |
Geek has developed an effective vaccine for Corona virus and he wants each of the N houses in Geek Land to have access to it. Given a binary tree where each node represents a house in Geek Land, find the minimum number of houses that should be supplied with the vaccine kit if one vaccine kit is sufficient for that hous... | NEED_VACCINE = 0
HAS_VACCINE = 1
NO_NEED_OF_VACCINE = 2
class Solution:
def supplyVaccine(self, root):
vaccineCount = [0]
if self._supplyVaccine(root, vaccineCount) == NEED_VACCINE:
vaccineCount[0] += 1
return vaccineCount[0]
def _supplyVaccine(self, root, vaccineCount):
... | ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER NUMBER RETURN VAR NUMBER FUNC_DEF IF VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER NUMBER RETURN VAR IF VAR VAR VAR VAR... |
Geek has developed an effective vaccine for Corona virus and he wants each of the N houses in Geek Land to have access to it. Given a binary tree where each node represents a house in Geek Land, find the minimum number of houses that should be supplied with the vaccine kit if one vaccine kit is sufficient for that hous... | class Solution:
def Vaccine(self, root):
global cnt
if root == None:
return 1
L = Solution().Vaccine(root.left)
R = Solution().Vaccine(root.right)
if L == 1 and R == 1:
return 2
elif L == 2 or R == 2:
cnt += 1
return 3
... | CLASS_DEF FUNC_DEF IF VAR NONE RETURN NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR RETURN BIN_OP VAR VAR NUMBER... |
Geek has developed an effective vaccine for Corona virus and he wants each of the N houses in Geek Land to have access to it. Given a binary tree where each node represents a house in Geek Land, find the minimum number of houses that should be supplied with the vaccine kit if one vaccine kit is sufficient for that hous... | global res
class Solution:
def supplyVaccine(self, root):
global res
res = 0
if root == None:
return 0
if dfs(root) == 0:
return 1 + res
else:
return res
def dfs(root):
if root == None:
return 2
lf = dfs(root.left)
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER IF VAR NONE RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN BIN_OP NUMBER VAR RETURN VAR FUNC_DEF IF VAR NONE RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN ... |
Geek has developed an effective vaccine for Corona virus and he wants each of the N houses in Geek Land to have access to it. Given a binary tree where each node represents a house in Geek Land, find the minimum number of houses that should be supplied with the vaccine kit if one vaccine kit is sufficient for that hous... | class Solution:
def traverse(self, root, count):
if root == None:
return 1
l = self.traverse(root.left, count)
r = self.traverse(root.right, count)
if l == -1 or r == -1:
count[0] += 1
return 0
if l == 0 or r == 0:
return 1
... | CLASS_DEF FUNC_DEF IF VAR NONE RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR LIST NUMBER IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER NUMBER RETURN VAR NUMBER |
Geek has developed an effective vaccine for Corona virus and he wants each of the N houses in Geek Land to have access to it. Given a binary tree where each node represents a house in Geek Land, find the minimum number of houses that should be supplied with the vaccine kit if one vaccine kit is sufficient for that hous... | class Solution:
def supplyVaccine(self, root):
def dfs(node):
if not node:
return float("inf"), 0, 0
l_kit, l_covered, l_notcovered = dfs(node.left)
r_kit, r_covered, r_notcovered = dfs(node.right)
kit = (
min(l_kit, l_covered... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR RETURN FUNC_CALL VAR STRING NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VA... |
Geek has developed an effective vaccine for Corona virus and he wants each of the N houses in Geek Land to have access to it. Given a binary tree where each node represents a house in Geek Land, find the minimum number of houses that should be supplied with the vaccine kit if one vaccine kit is sufficient for that hous... | class Solution:
def supplyVaccine(self, root):
def traverse(head, root, ans):
if not root:
return 0
l = traverse(head, root.left, ans)
r = traverse(head, root.right, ans)
if root == head:
if max(l, r) == -1 and min(l, r) == -1... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER RETURN NUMBER VAR NUMBER NUMBER RETURN NUMBER IF B... |
Geek has developed an effective vaccine for Corona virus and he wants each of the N houses in Geek Land to have access to it. Given a binary tree where each node represents a house in Geek Land, find the minimum number of houses that should be supplied with the vaccine kit if one vaccine kit is sufficient for that hous... | class Solution:
def supplyVaccine(self, root):
cnt = [0]
def solve(root):
if not root:
return 0
left = solve(root.left)
right = solve(root.right)
if left == -1 or right == -1:
cnt[0] += 1
return 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER RETURN VAR NUMBER |
Geek has developed an effective vaccine for Corona virus and he wants each of the N houses in Geek Land to have access to it. Given a binary tree where each node represents a house in Geek Land, find the minimum number of houses that should be supplied with the vaccine kit if one vaccine kit is sufficient for that hous... | class Solution:
def supplyVaccine(self, root):
v = 0
def solve(node):
nonlocal v
if not node:
return 0
l = solve(node.left)
r = solve(node.right)
if l == 1 or r == 1:
v += 1
if l == 0:
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER RETURN BIN_OP BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUM... |
Geek has developed an effective vaccine for Corona virus and he wants each of the N houses in Geek Land to have access to it. Given a binary tree where each node represents a house in Geek Land, find the minimum number of houses that should be supplied with the vaccine kit if one vaccine kit is sufficient for that hous... | novaccine = 0
class Solution:
def supplyVaccine(self, root):
if self.vaccine(root) == "want":
global novaccine
novaccine += 1
ans = novaccine
novaccine = 0
return ans
def vaccine(self, root):
if not root:
return "ok"
left = ... | ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR STRING VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER RETURN VAR FUNC_DEF IF VAR RETURN STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR STRING VAR NUMBER RETURN STRING IF VAR STRING VAR STRING RETURN STRING RETURN STRING |
Geek has developed an effective vaccine for Corona virus and he wants each of the N houses in Geek Land to have access to it. Given a binary tree where each node represents a house in Geek Land, find the minimum number of houses that should be supplied with the vaccine kit if one vaccine kit is sufficient for that hous... | class Solution:
def supplyVaccine(self, root):
a, b = self.cnt(root)
return a + b // 2
def cnt(self, node):
if not node.left and not node.right:
return 0, 2
la, lb = self.cnt(node.left) if node.left else (0, 3)
ra, rb = self.cnt(node.right) if node.right els... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR RETURN BIN_OP VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VA... |
Geek has developed an effective vaccine for Corona virus and he wants each of the N houses in Geek Land to have access to it. Given a binary tree where each node represents a house in Geek Land, find the minimum number of houses that should be supplied with the vaccine kit if one vaccine kit is sufficient for that hous... | import sys
sys.setrecursionlimit(10**6)
class Solution:
def __init__(self):
self.vaccine = 0
def vaccine_needed(self, root):
if root is None:
return -1
left = self.vaccine_needed(root.left)
right = self.vaccine_needed(root.right)
if left == 1 or right == ... | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FUNC_DEF IF VAR NONE RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF FUNC_CALL ... |
Geek has developed an effective vaccine for Corona virus and he wants each of the N houses in Geek Land to have access to it. Given a binary tree where each node represents a house in Geek Land, find the minimum number of houses that should be supplied with the vaccine kit if one vaccine kit is sufficient for that hous... | class Solution:
def supplyVaccine(self, root):
if not root:
return 0
if not root.left and not root.right:
return 1
self.count = 0
self.needs = 1
self.covered = 2
self.has_vaccine_kit = 3
self.not_need = 4
if self.needs == self.... | CLASS_DEF FUNC_DEF IF VAR RETURN NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR FUNC_DEF IF VAR RETURN VAR IF VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ... |
Geek has developed an effective vaccine for Corona virus and he wants each of the N houses in Geek Land to have access to it. Given a binary tree where each node represents a house in Geek Land, find the minimum number of houses that should be supplied with the vaccine kit if one vaccine kit is sufficient for that hous... | class Solution:
def __init__(self):
self.vac_count = 0
def rec_count(self, root):
if root == None:
return 0
if root.left == None and root.right == None:
return -1
lc = self.rec_count(root.left)
rc = self.rec_count(root.right)
if lc == -1 ... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FUNC_DEF IF VAR NONE RETURN NUMBER IF VAR NONE VAR NONE RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF ASSI... |
Geek has developed an effective vaccine for Corona virus and he wants each of the N houses in Geek Land to have access to it. Given a binary tree where each node represents a house in Geek Land, find the minimum number of houses that should be supplied with the vaccine kit if one vaccine kit is sufficient for that hous... | class Solution:
def supplyVaccine(self, root):
def dfs(node):
if not node:
return 1
l = dfs(node.left)
r = dfs(node.right)
if l == 0 or r == 0:
self.sum += 1
return 2
elif l == 2 or r == 2:
... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER RETURN VAR |
Geek has developed an effective vaccine for Corona virus and he wants each of the N houses in Geek Land to have access to it. Given a binary tree where each node represents a house in Geek Land, find the minimum number of houses that should be supplied with the vaccine kit if one vaccine kit is sufficient for that hous... | class Solution:
def supplyVaccine(self, root):
self.vaxKit = 0
res = self.supplyVaccineRecursive(root)
if res == -1:
self.vaxKit += 1
return self.vaxKit
def supplyVaccineRecursive(self, root):
if not (root.left or root.right):
return -1
e... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER R... |
Geek has developed an effective vaccine for Corona virus and he wants each of the N houses in Geek Land to have access to it. Given a binary tree where each node represents a house in Geek Land, find the minimum number of houses that should be supplied with the vaccine kit if one vaccine kit is sufficient for that hous... | ans = 0
def mgc(root):
global ans
if not root:
return 1
left = mgc(root.left)
right = mgc(root.right)
if left == 1 and right == 1:
return 2
elif left == 2 or right == 2:
ans += 1
return 3
return 1
class Solution:
def supplyVaccine(self, root):
... | ASSIGN VAR NUMBER FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER RETURN VAR |
Geek has developed an effective vaccine for Corona virus and he wants each of the N houses in Geek Land to have access to it. Given a binary tree where each node represents a house in Geek Land, find the minimum number of houses that should be supplied with the vaccine kit if one vaccine kit is sufficient for that hous... | class Solution:
def supplyVaccine(self, root):
global ans
ans = 0
if self.vaccine(root) == "want":
ans += 1
return ans
def vaccine(self, root):
global ans
if root == None:
return "ok"
left = self.vaccine(root.left)
right =... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR STRING VAR NUMBER RETURN VAR FUNC_DEF IF VAR NONE RETURN STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR STRING VAR NUMBER RETURN STRING IF VAR STRING VAR STRING RETURN STRING RETURN STRING |
Geek has developed an effective vaccine for Corona virus and he wants each of the N houses in Geek Land to have access to it. Given a binary tree where each node represents a house in Geek Land, find the minimum number of houses that should be supplied with the vaccine kit if one vaccine kit is sufficient for that hous... | class Solution:
number = 0
def rec_count_vaccine(self, root):
if root is None:
return True, False
L_got_vac, L_own_vac = self.rec_count_vaccine(root.left)
R_got_vac, R_own_vac = self.rec_count_vaccine(root.right)
root_got_vac = False
root_own_vac = False
... | CLASS_DEF ASSIGN VAR NUMBER FUNC_DEF IF VAR NONE RETURN NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CAL... |
Geek has developed an effective vaccine for Corona virus and he wants each of the N houses in Geek Land to have access to it. Given a binary tree where each node represents a house in Geek Land, find the minimum number of houses that should be supplied with the vaccine kit if one vaccine kit is sufficient for that hous... | is_fed = {None: False}
def check_fed(node):
if node in is_fed.keys():
return True
return False
def feed(gp, root, cnt):
if root is None:
return cnt
cnt = feed(root, root.left, cnt)
cnt = feed(root, root.right, cnt)
if (
root.left is not None
and not check_fed(... | ASSIGN VAR DICT NONE NUMBER FUNC_DEF IF VAR FUNC_CALL VAR RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR NONE RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NONE FUNC_CALL VAR VAR VAR NONE FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIG... |
Geek has developed an effective vaccine for Corona virus and he wants each of the N houses in Geek Land to have access to it. Given a binary tree where each node represents a house in Geek Land, find the minimum number of houses that should be supplied with the vaccine kit if one vaccine kit is sufficient for that hous... | class Solution:
def supplyVaccine(self, root):
self.ans = 0
covered = {None}
def dfs(node, par=None):
if node:
dfs(node.left, node)
dfs(node.right, node)
if (
par is None
and node not in cov... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NONE FUNC_DEF NONE IF VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR NONE VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR |
Geek has developed an effective vaccine for Corona virus and he wants each of the N houses in Geek Land to have access to it. Given a binary tree where each node represents a house in Geek Land, find the minimum number of houses that should be supplied with the vaccine kit if one vaccine kit is sufficient for that hous... | class Solution:
def traverse(self, n):
if not n:
return 0, 2
vaccineKitL, distL = self.traverse(n.left)
vaccineKitR, distR = self.traverse(n.right)
if max(distL, distR) == 3:
return vaccineKitL + vaccineKitR + 1, 1
return vaccineKitL + vaccineKitR, 1 ... | CLASS_DEF FUNC_DEF IF VAR RETURN NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN BIN_OP VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN BIN_OP VAR ... |
Geek has developed an effective vaccine for Corona virus and he wants each of the N houses in Geek Land to have access to it. Given a binary tree where each node represents a house in Geek Land, find the minimum number of houses that should be supplied with the vaccine kit if one vaccine kit is sufficient for that hous... | class Solution:
def util(self, root, ans):
if root is None:
return "mnc"
left = self.util(root.left, ans)
right = self.util(root.right, ans)
if left == "nm" or right == "nm":
ans[0] += 1
return "mwc"
if left == "mnc" and right == "mnc":
... | CLASS_DEF FUNC_DEF IF VAR NONE RETURN STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING VAR STRING VAR NUMBER NUMBER RETURN STRING IF VAR STRING VAR STRING RETURN STRING RETURN STRING FUNC_DEF ASSIGN VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING VAR NUMBER NUMBER RE... |
Geek has developed an effective vaccine for Corona virus and he wants each of the N houses in Geek Land to have access to it. Given a binary tree where each node represents a house in Geek Land, find the minimum number of houses that should be supplied with the vaccine kit if one vaccine kit is sufficient for that hous... | class Solution:
def supplyVaccine(self, root):
self.count = 0
def supply(par, root):
if not root:
return False
if not root.left and not root.right:
return True
if supply(root, root.left):
root.data = 0
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FUNC_DEF IF VAR RETURN NUMBER IF VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER RETURN NUMBER IF VAR VAR NUMBE... |
Geek has developed an effective vaccine for Corona virus and he wants each of the N houses in Geek Land to have access to it. Given a binary tree where each node represents a house in Geek Land, find the minimum number of houses that should be supplied with the vaccine kit if one vaccine kit is sufficient for that hous... | class Solution:
def supplyVaccine(self, root):
ans = [0]
if self.recursion(root, ans) == 0:
ans[0] += 1
return ans[0]
def recursion(self, root, ans):
if root is None:
return 1
left = self.recursion(root.left, ans)
right = self.recursion(r... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER NUMBER RETURN VAR NUMBER FUNC_DEF IF VAR NONE RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER |
Given a non-empty array of unique positive integers A, consider the following graph:
There are A.length nodes, labelled A[0] to A[A.length - 1];
There is an edge between A[i] and A[j] if and only if A[i] and A[j] share a common factor greater than 1.
Return the size of the largest connected component in the graph.
... | class DUS(object):
def __init__(self, n):
self.p = [*list(range(n))]
self.size = [1] * n
def Find(self, x):
if self.p[x] == x:
return x
tmp = []
while self.p[x] != x:
tmp.append(x)
x = self.p[x]
for t in tmp:
self.... | CLASS_DEF VAR FUNC_DEF ASSIGN VAR LIST FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF IF VAR VAR VAR RETURN VAR ASSIGN VAR LIST WHILE VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR... |
Given a non-empty array of unique positive integers A, consider the following graph:
There are A.length nodes, labelled A[0] to A[A.length - 1];
There is an edge between A[i] and A[j] if and only if A[i] and A[j] share a common factor greater than 1.
Return the size of the largest connected component in the graph.
... | class UnionFind(object):
def uf(self, n):
self.uf = [i for i in range(n)]
self.size = [1] * n
def find(self, x):
while x != self.uf[x]:
self.uf[x] = self.uf[self.uf[x]]
x = self.uf[x]
return self.uf[x]
def union(self, x, y):
x_root = self.fi... | CLASS_DEF VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF WHILE VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN ASSIGN VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUM... |
Given a non-empty array of unique positive integers A, consider the following graph:
There are A.length nodes, labelled A[0] to A[A.length - 1];
There is an edge between A[i] and A[j] if and only if A[i] and A[j] share a common factor greater than 1.
Return the size of the largest connected component in the graph.
... | class FU:
def __init__(self, n):
self.p = [i for i in range(n)]
def find(self, x):
if self.p[x] != x:
self.p[x] = self.find(self.p[x])
return self.p[x]
def union(self, x, y):
px, py = self.find(x), self.find(y)
self.p[py] = px
class Solution:
def... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR V... |
Given a non-empty array of unique positive integers A, consider the following graph:
There are A.length nodes, labelled A[0] to A[A.length - 1];
There is an edge between A[i] and A[j] if and only if A[i] and A[j] share a common factor greater than 1.
Return the size of the largest connected component in the graph.
... | class DSU:
def __init__(self, count):
self.parent = [i for i in range(count)]
self.size = [(1) for _ in range(count)]
self.max = 0
def find(self, x):
root = x
while root != self.parent[root]:
root = self.parent[root]
while x != root:
next... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR WHILE VAR VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR ... |
Given a non-empty array of unique positive integers A, consider the following graph:
There are A.length nodes, labelled A[0] to A[A.length - 1];
There is an edge between A[i] and A[j] if and only if A[i] and A[j] share a common factor greater than 1.
Return the size of the largest connected component in the graph.
... | class Solution:
def largestComponentSize(self, A: List[int]) -> int:
parent = [-1] * 1000001
def _find(a):
if parent[a] == -1:
return a
parent[a] = _find(parent[a])
return parent[a]
def _union(a, b):
ap = _find(a)
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_DEF IF VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR FUNC_CA... |
Given a non-empty array of unique positive integers A, consider the following graph:
There are A.length nodes, labelled A[0] to A[A.length - 1];
There is an edge between A[i] and A[j] if and only if A[i] and A[j] share a common factor greater than 1.
Return the size of the largest connected component in the graph.
... | class Solution:
def largestComponentSize(self, A: List[int]) -> int:
parent = [-1] * 100001
def find(x):
if parent[x] == -1:
return x
parent[x] = find(parent[x])
return parent[x]
def union(x, y):
xp, yp = find(x), find(y)
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_DEF IF VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR ... |
Given a non-empty array of unique positive integers A, consider the following graph:
There are A.length nodes, labelled A[0] to A[A.length - 1];
There is an edge between A[i] and A[j] if and only if A[i] and A[j] share a common factor greater than 1.
Return the size of the largest connected component in the graph.
... | class Primes:
def __init__(self, N):
self.N = N
self.primes = [0] * (N + 1)
self.get_primes()
def get_primes(self):
for i in range(2, self.N + 1):
if self.primes[i] == 0:
self.primes[i] = i
upto = self.N // i
for j in ... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VA... |
Given a non-empty array of unique positive integers A, consider the following graph:
There are A.length nodes, labelled A[0] to A[A.length - 1];
There is an edge between A[i] and A[j] if and only if A[i] and A[j] share a common factor greater than 1.
Return the size of the largest connected component in the graph.
... | class Solution:
def largestComponentSize(self, A: List[int]) -> int:
count = [(1) for _ in A]
parent = [i for i in range(len(A))]
def find_it(index):
while index != parent[index]:
index = parent[index]
return index
def union_it(index1, index... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF WHILE VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR RETURN IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSI... |
Given a non-empty array of unique positive integers A, consider the following graph:
There are A.length nodes, labelled A[0] to A[A.length - 1];
There is an edge between A[i] and A[j] if and only if A[i] and A[j] share a common factor greater than 1.
Return the size of the largest connected component in the graph.
... | class Solution:
def largestComponentSize(self, A: List[int]) -> int:
self.uf_table = [idx for idx in range(100001)]
def find(p):
if self.uf_table[p] != p:
self.uf_table[p] = find(self.uf_table[p])
return self.uf_table[p]
def union(p, q):
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR ... |
Given a non-empty array of unique positive integers A, consider the following graph:
There are A.length nodes, labelled A[0] to A[A.length - 1];
There is an edge between A[i] and A[j] if and only if A[i] and A[j] share a common factor greater than 1.
Return the size of the largest connected component in the graph.
... | primes = [
2,
3,
5,
7,
11,
13,
17,
19,
23,
29,
31,
37,
41,
43,
47,
53,
59,
61,
67,
71,
73,
79,
83,
89,
97,
101,
103,
107,
109,
113,
127,
131,
137,
139,
149,
151,
157,
1... | ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUM... |
Given a non-empty array of unique positive integers A, consider the following graph:
There are A.length nodes, labelled A[0] to A[A.length - 1];
There is an edge between A[i] and A[j] if and only if A[i] and A[j] share a common factor greater than 1.
Return the size of the largest connected component in the graph.
... | class Solution:
def largestComponentSize(self, A: List[int]) -> int:
def prime_factors(n):
for i in range(2, int(math.sqrt(n)) + 1):
if n % i == 0:
return prime_factors(n // i) | set([i])
return set([n])
f = list(range(len(A)))
... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR LIST VAR RETURN FUNC_CALL VAR LIST VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR VAR ASSIGN ... |
Given a non-empty array of unique positive integers A, consider the following graph:
There are A.length nodes, labelled A[0] to A[A.length - 1];
There is an edge between A[i] and A[j] if and only if A[i] and A[j] share a common factor greater than 1.
Return the size of the largest connected component in the graph.
... | class Solution:
def largestComponentSize(self, A: List[int]) -> int:
uf = {}
rank = {i: (1) for i in range(len(A))}
def find(x):
uf.setdefault(x, x)
if uf[x] != x:
uf[x] = find(uf[x])
return uf[x]
def union(x, y):
px,... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR... |
Given a non-empty array of unique positive integers A, consider the following graph:
There are A.length nodes, labelled A[0] to A[A.length - 1];
There is an edge between A[i] and A[j] if and only if A[i] and A[j] share a common factor greater than 1.
Return the size of the largest connected component in the graph.
... | class DSU:
def __init__(self, n):
self.p = list(range(n))
self.sz = [1] * n
def find(self, x):
if x == self.p[x]:
return x
self.p[x] = self.find(self.p[x])
return self.p[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF IF VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR... |
Given a non-empty array of unique positive integers A, consider the following graph:
There are A.length nodes, labelled A[0] to A[A.length - 1];
There is an edge between A[i] and A[j] if and only if A[i] and A[j] share a common factor greater than 1.
Return the size of the largest connected component in the graph.
... | class DSU:
def __init__(self, N):
self.p = list(range(N))
def find(self, x):
if self.p[x] != x:
self.p[x] = self.find(self.p[x])
return self.p[x]
def union(self, x, y):
xr, yr = self.find(x), self.find(y)
self.p[xr] = yr
class Solution:
def prime... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP... |
Given a non-empty array of unique positive integers A, consider the following graph:
There are A.length nodes, labelled A[0] to A[A.length - 1];
There is an edge between A[i] and A[j] if and only if A[i] and A[j] share a common factor greater than 1.
Return the size of the largest connected component in the graph.
... | class UnionFind:
def __init__(self, A):
self._arr = {v: (-1) for v in A}
def union(self, u, v):
p1 = self.find(u)
p2 = self.find(v)
if p1 != p2:
self._arr[p1] = p2
return True
return False
def find(self, u):
if self._arr.get(u, -1) =... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF IF FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL... |
Given a non-empty array of unique positive integers A, consider the following graph:
There are A.length nodes, labelled A[0] to A[A.length - 1];
There is an edge between A[i] and A[j] if and only if A[i] and A[j] share a common factor greater than 1.
Return the size of the largest connected component in the graph.
... | class Solution:
def largestComponentSize(self, A: List[int]) -> int:
def find(u):
if p[u] == -1:
return u
p[u] = find(p[u])
return p[u]
def union(u, v):
u = find(u)
v = find(v)
if u != v:
if r[... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC... |
Given a non-empty array of unique positive integers A, consider the following graph:
There are A.length nodes, labelled A[0] to A[A.length - 1];
There is an edge between A[i] and A[j] if and only if A[i] and A[j] share a common factor greater than 1.
Return the size of the largest connected component in the graph.
... | class Solution:
def get_prime_numbers(self, num_to_idx_dict, max_num: int) -> List[int]:
is_prime_list = [True] * (max_num + 1)
prime_to_nums_dict = defaultdict(list)
for i in range(2, max_num // 2 + 1):
if is_prime_list[i] == False:
continue
num = i
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR VAR RETURN VAR VAR VAR FUNC_DEF VAR IF VAR V... |
Given a non-empty array of unique positive integers A, consider the following graph:
There are A.length nodes, labelled A[0] to A[A.length - 1];
There is an edge between A[i] and A[j] if and only if A[i] and A[j] share a common factor greater than 1.
Return the size of the largest connected component in the graph.
... | class Solution:
def largestComponentSize(self, A: List[int]) -> int:
primes = [
2,
3,
5,
7,
11,
13,
17,
19,
23,
29,
31,
37,
41,
43,
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMB... |
Given a non-empty array of unique positive integers A, consider the following graph:
There are A.length nodes, labelled A[0] to A[A.length - 1];
There is an edge between A[i] and A[j] if and only if A[i] and A[j] share a common factor greater than 1.
Return the size of the largest connected component in the graph.
... | class DisjointSetUnion(object):
def __init__(self, size):
self.parent = [i for i in range(size + 1)]
self.size = [1] * (size + 1)
def find(self, x):
if self.parent[x] != x:
self.parent[x] = self.find(self.parent[x])
return self.parent[x]
def union(self, x, y):
... | CLASS_DEF VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR RETURN VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VA... |
Given a non-empty array of unique positive integers A, consider the following graph:
There are A.length nodes, labelled A[0] to A[A.length - 1];
There is an edge between A[i] and A[j] if and only if A[i] and A[j] share a common factor greater than 1.
Return the size of the largest connected component in the graph.
... | max_num = 100000
smallest_prime_factors = [None] * (max_num + 1)
smallest_prime_factors[1] = 1
for num in range(2, max_num + 1):
if smallest_prime_factors[num] is not None:
continue
smallest_prime_factors[num] = num
for multiple in range(num * num, max_num + 1, num):
if smallest_prime_factor... | ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NONE ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR NONE ASSIGN VAR VAR VAR CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT FUNC_DEF IF ... |
Given a non-empty array of unique positive integers A, consider the following graph:
There are A.length nodes, labelled A[0] to A[A.length - 1];
There is an edge between A[i] and A[j] if and only if A[i] and A[j] share a common factor greater than 1.
Return the size of the largest connected component in the graph.
... | class UnionFind:
def __init__(self, length):
self.parents = {num: num for num in range(length)}
self.ranks = {num: (1) for num in range(length)}
def find(self, src):
if self.parents[src] == src:
return src
self.parents[src] = self.find(self.parents[src])
ret... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VA... |
Given a non-empty array of unique positive integers A, consider the following graph:
There are A.length nodes, labelled A[0] to A[A.length - 1];
There is an edge between A[i] and A[j] if and only if A[i] and A[j] share a common factor greater than 1.
Return the size of the largest connected component in the graph.
... | class UnionFindSet:
def __init__(self, n):
self.parents = list(range(n))
self.ranks = [1] * n
def find(self, u):
if u != self.parents[u]:
self.parents[u] = self.find(self.parents[u])
return self.parents[u]
def union(self, u, v):
pu, pv = self.find(u), s... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF IF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR IF VAR VA... |
Given a non-empty array of unique positive integers A, consider the following graph:
There are A.length nodes, labelled A[0] to A[A.length - 1];
There is an edge between A[i] and A[j] if and only if A[i] and A[j] share a common factor greater than 1.
Return the size of the largest connected component in the graph.
... | class UFS:
def __init__(self, N):
self._parent = list(range(N))
def find(self, x):
if self._parent[x] != x:
self._parent[x] = self.find(self._parent[x])
return self._parent[x]
def union(self, x, y):
xroot, yroot = self.find(x), self.find(y)
if xroot != ... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR WHILE BIN_OP VAR NUMBER NUMBER ... |
Given a non-empty array of unique positive integers A, consider the following graph:
There are A.length nodes, labelled A[0] to A[A.length - 1];
There is an edge between A[i] and A[j] if and only if A[i] and A[j] share a common factor greater than 1.
Return the size of the largest connected component in the graph.
... | class Solution:
def largestComponentSize(self, A: List[int]) -> int:
factor = {}
dsu = DSU()
def get_primes(num):
primes = set()
i = 2
while i * i <= num:
if num % i == 0:
while num % i == 0:
nu... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR FOR VAR VAR AS... |
Given a non-empty array of unique positive integers A, consider the following graph:
There are A.length nodes, labelled A[0] to A[A.length - 1];
There is an edge between A[i] and A[j] if and only if A[i] and A[j] share a common factor greater than 1.
Return the size of the largest connected component in the graph.
... | class Solution:
def largestComponentSize(self, A: List[int]) -> int:
f = {}
def find(x):
f.setdefault(x, x)
if x != f[x]:
f[x] = find(f[x])
return f[x]
def union(x, y):
px, py = find(x), find(y)
if px != py:
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT FUNC_DEF EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ... |
Given a non-empty array of unique positive integers A, consider the following graph:
There are A.length nodes, labelled A[0] to A[A.length - 1];
There is an edge between A[i] and A[j] if and only if A[i] and A[j] share a common factor greater than 1.
Return the size of the largest connected component in the graph.
... | class Solution:
def largestComponentSize(self, A: List[int]) -> int:
n = len(A)
cnt = dict([(num, 1) for num in A])
par = dict([(num, num) for num in A])
def find(num):
nonlocal par
if par[num] != num:
par[num] = find(par[num])
re... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF IF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR RETURN IF VAR VAR ASSIGN VAR VAR... |
Given a non-empty array of unique positive integers A, consider the following graph:
There are A.length nodes, labelled A[0] to A[A.length - 1];
There is an edge between A[i] and A[j] if and only if A[i] and A[j] share a common factor greater than 1.
Return the size of the largest connected component in the graph.
... | class Solution:
def largestComponentSize(self, A: List[int]) -> int:
def decompose(n):
def rec(n, start):
for i in range(start, int(math.sqrt(n)) + 1, 2):
if n % i == 0:
return rec(n // i, i) | {i}
return {n}
... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF FUNC_DEF FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR RETURN VAR IF BIN_OP VAR NUMBER NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN BIN_... |
Given a non-empty array of unique positive integers A, consider the following graph:
There are A.length nodes, labelled A[0] to A[A.length - 1];
There is an edge between A[i] and A[j] if and only if A[i] and A[j] share a common factor greater than 1.
Return the size of the largest connected component in the graph.
... | class UnionFind:
def __init__(self, maxval):
self.arr = [i for i in range(maxval)]
def find(self, n):
if n != self.arr[n]:
self.arr[n] = self.find(self.arr[n])
return self.arr[n]
def union(self, a, b):
self.arr[self.find(a)] = self.arr[self.find(b)]
class Sol... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR FUNC_CALL... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.