description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Given a binary matrix M with R rows and C columns, where each element of the matrix will be 0 or 1. Find the largest square that can be formed with center (i, j) and contains atmost K 1s. There are Q queries, a single query has two integers denoting the centre (i,j) of the square.
Example 1:
Input:
R = 4, C = 5
M = {... | class Solution:
def largestSquare(self, M, R, C, K, Q, q_i, q_j):
for i in range(1, R):
M[i][0] += M[i - 1][0]
for i in range(1, C):
M[0][i] += M[0][i - 1]
for i in range(1, R):
for j in range(1, C):
M[i][j] = M[i - 1][j] + M[i][j - 1] - M... | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP ... |
Given a binary matrix M with R rows and C columns, where each element of the matrix will be 0 or 1. Find the largest square that can be formed with center (i, j) and contains atmost K 1s. There are Q queries, a single query has two integers denoting the centre (i,j) of the square.
Example 1:
Input:
R = 4, C = 5
M = {... | class Solution:
def binarysearch(self, l, r, dp, k, i, j):
if l <= r:
mid = (l + r) // 2
x1 = i - mid
x2 = i + mid
y1 = j - mid
y2 = j + mid
count = dp[x2][y2]
if x1 > 0:
count -= dp[x1 - 1][y2]
... | CLASS_DEF FUNC_DEF IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR BI... |
Given a binary matrix M with R rows and C columns, where each element of the matrix will be 0 or 1. Find the largest square that can be formed with center (i, j) and contains atmost K 1s. There are Q queries, a single query has two integers denoting the centre (i,j) of the square.
Example 1:
Input:
R = 4, C = 5
M = {... | class Solution:
def getMinDistanceFromSides(self, R, C, x, y):
return min(x - 0, y - 0, R - 1 - x, C - 1 - y)
def getSubMatSum(self, prefix, x1, y1, x2, y2):
left = prefix[x2][y1 - 1] if y1 > 0 else 0
right = prefix[x1 - 1][y2] if x1 > 0 else 0
top = prefix[x1 - 1][y1 - 1] if x... | CLASS_DEF FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR N... |
Given a binary matrix M with R rows and C columns, where each element of the matrix will be 0 or 1. Find the largest square that can be formed with center (i, j) and contains atmost K 1s. There are Q queries, a single query has two integers denoting the centre (i,j) of the square.
Example 1:
Input:
R = 4, C = 5
M = {... | class Solution:
def largestSquare(self, M, R, C, K, Q, q_i, q_j):
def check_range_sum(i, j, k):
r1, c1 = i - k, j - k
r2, c2 = i + k, j + k
if r1 < 0 or c1 < 0 or r2 >= R or c2 >= C:
return K + 1
return (
ps_mat[r2 + 1][c2 + 1... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR RETURN BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSI... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | def leftup(i, S, prefix, count):
left = 0
right = i - 1
if S[i] >= prefix[i - 1] - prefix[left]:
count[left] += 1
count[i] -= 1
return count
elif S[i] < S[i - 1]:
count[right] += 1
count[i] -= 1
return count
else:
pos = right
while left... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR NUMBER RETURN VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR BIN_OP VAR... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | t = int(input())
for i in range(t):
N = int(input())
minions = [int(i) for i in input().split()]
votes = [(0) for i in range(N)]
for i in range(N):
j = i + 1
z = 0
while j < N:
if minions[i] >= z:
votes[j] += 1
z += minions[j]
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER VA... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | t = int(input())
for _ in range(t):
n = int(input())
s = list(map(int, input().split()))
pre = [s[0]]
for i in range(1, n):
pre.append(pre[-1] + s[i])
li = [0] * n
li[0], li[-1] = 1, 1
if n == 1:
print(0)
else:
for i in range(1, n - 1):
li[i] = 2
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | t = int(input())
for j in range(t):
s = int(input())
a = []
b = []
s1 = [0]
for j in input().split():
a.append(int(j))
b.append(0)
s1.append(s1[-1] + a[-1])
del s1[0]
for j in range(0, s):
for i in range(j + 1, s):
if a[j] >= s1[i] - s1[j] - a[i]:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
s = [0] * n
s[0] = a[0]
for j in range(1, n):
s[j] = s[j - 1] + a[j]
ans = [0] * n
for j in range(n):
k = j + 1
while k < n:
if a[j] >= s[k - 1] - s[j]:
ans[... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_O... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | T = int(input())
while T:
n = int(input())
l = [0]
l += list(map(int, input().split()))
v = [0] * (n + 1)
s = [0] * (n + 1)
for i in range(1, n + 1):
s[i] = s[i - 1] + l[i]
for i in range(1, n + 1):
for j in range(i - 1, 0, -1):
if l[i] < s[i - 1] - s[j]:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | t = int(input())
for i in range(t):
n = int(input())
s = list(map(int, input().split()))
if n == 1:
print("0")
elif n == 2:
print("1 1")
else:
co = [0] * n
for j in range(n):
cs, k = 0, j + 1
while k < n and cs <= s[j]:
co[k] +=... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VA... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | for i in range(int(input())):
n, lst = int(input()), list(map(int, input().split()))
p, l2 = 0, []
for i in lst:
p += i
l2.append(p)
t = [(0) for i in range(n)]
for j in range(n):
p = 0
for k in range(j - 1, -1, -1):
p += lst[k]
if p - lst[k] <... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER LIST FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | T = int(input())
for i in range(T):
n = int(input())
l = list(map(int, input().split()))
L = [0] * n
for j in range(n):
s = 0
for k in range(j + 1, n):
if s <= l[j]:
L[k] += 1
s += l[k]
else:
break
s = 0
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMB... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | for _ in range(int(input())):
N = int(input())
s = list(map(int, input().split()))
v = [0] * N
for i in range(N):
inf = 0
j = i + 1
while j < N and s[i] >= inf:
v[j] += 1
inf += s[j]
j += 1
for i in range(N - 1, -1, -1):
inf = 0
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR ... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | t = int(input())
while t > 0:
n = int(input())
a = list(map(int, input().split()))
v = [0] * n
for i in range(n):
s1 = 0
s2 = 0
if i + 1 < n:
v[i + 1] += 1
if i - 1 >= 0:
v[i - 1] += 1
for j in range(i + 1, n):
s1 = s1 + a[j]
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER IF BIN_O... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | t = int(input().strip())
while t:
n = int(input().strip())
a = [int(x) for x in input().strip().split()]
b = [0] * n
for i in range(n):
inf = a[i]
j = i + 1
while inf >= 0 and i != n - 1 and j < n:
b[j] += 1
inf -= a[j]
j += 1
inf = a[i... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBE... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | t = int(input())
for _ in range(t):
n = int(input())
influences = list(map(int, input().split()))
rev_infl = list(reversed(influences[:]))
sums = influences[:]
rsums = rev_infl
for i in range(1, n):
sums[i] += sums[i - 1]
rsums[i] += rsums[i - 1]
votes = [0] * n
for i in ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR B... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | def forward(array, index, vote_array):
sum = 0
j = index + 1
size = len(array)
vote_array[j] += 1
while j < size - 1:
sum += array[j]
if sum <= array[index]:
j += 1
vote_array[j] += 1
else:
break
def reverse(array, index, vote_array):
... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER WHILE VAR NUMBER VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR VAR NUMBE... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | t = int(input())
for z in range(t):
n = int(input())
s = [int(x) for x in input().split()]
CurrSum = 0
Ci = 0
AnsArray = [0] * n
AnsArray[0] = 1
for i in range(n - 1):
CurrSum = 0
Ci = i + 1
while CurrSum <= s[i] and Ci < n:
CurrSum += s[Ci]
Ci... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | t = int(input())
while t:
n = int(input())
arr = [int(i) for i in input().split()]
br = [0] * (n + 1)
for i in range(n):
sums = 0
for j in range(i + 1, n):
if sums <= arr[i]:
br[j] += 1
else:
break
sums += arr[j]
for... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER VAR VAR V... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
for i in range(n - 1):
s = 0
for j in range(i + 1, n):
if s <= a[i]:
ans[j] += 1
else:
break
s += a[j]
for i in range(n... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBE... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | for t in range(int(input())):
n = int(input())
s = list(map(int, input().strip().split()))
vote = [(0) for i in range(n)]
for i in range(n):
influence = 0
voting = s[i]
for j in range(i + 1, n):
if voting >= influence:
vote[j] += 1
else:
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR ... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | for _ in range(int(input())):
n = int(input())
arr1 = list(map(int, input().split()))
Answer = [0] * n
for i in range(0, n):
j = i + 1
x = 0
while j < n:
if arr1[i] >= x:
Answer[j] += 1
x += arr1[j]
else:
bre... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR VA... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | n = int(input())
r = []
q = []
a = []
p = []
for i in range(0, n):
d = int(input())
a.append(d)
p = [int(x) for x in input().split(" ")]
q.append(p)
x = 0
for i in range(0, n):
u = []
m = 0
for o in range(0, a[i]):
u.append(m)
for j in range(0, len(q[i])):
s = 0
f... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | def findRight(preSum, L, R, val):
while L < R:
M = (L + R + 1) // 2
if preSum[M] <= val:
L = M
else:
R = M - 1
return L
def handle(nums):
n = len(nums)
votes = [0] * n
preSum = [0] * (n + 1)
for i, k in enumerate(nums):
preSum[i + 1] = pr... | FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR N... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | res = []
def getSum(nums, sums, i, j):
if j > i:
return sums[j] - nums[j] - sums[i]
elif i > j:
return sums[i] - nums[i] - sums[j]
else:
return 0
for _ in range(0, int(input())):
n = input()
nums = list(map(int, input().split(" ")))
sums = [0] * len(nums)
sums[0] ... | ASSIGN VAR LIST FUNC_DEF IF VAR VAR RETURN BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR RETURN BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BI... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | y = int(input())
number = [(0) for P in range(y)]
s = [[] for Q in range(y)]
for I in range(y):
number[I] = int(input())
l = input().split()
for a in range(number[I]):
s[I].append(int(l[a]))
v = [[] for R in range(y)]
for I in range(y):
if number[I] > 1:
v[I].append(1)
for D in r... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST VAR FUNC... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | T = int(input())
for i in range(T):
N = int(input())
A = list(map(int, input().split(" ")))
vote = [0] * N
cs = list()
sum = 0
for x in A:
sum = sum + x
cs.append(sum)
for i in range(N):
for j in range(i - 1, -1, -1):
if cs[i - 1] - cs[j] <= A[i]:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR FOR ... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | def leftsearch(prefs, n, l, h, k, i):
while l <= h:
m = (l + h) // 2
if prefs[i - 1] - prefs[m] > k:
l = m + 1
elif m > 0:
if prefs[i - 1] - prefs[m - 1] > k:
return m
else:
h = m - 1
else:
return m
r... | FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR RETURN VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR RETURN NUMBER FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | tst = int(input())
st = []
d = 0
for x in range(0, tst):
num = int(input())
arr = [int(y) for y in input().split(" ")]
lst = []
n = 0
for i in range(0, num):
lst.append(n)
for j in range(0, len(arr)):
cnt = 0
for k in range(j + 1, len(arr), 1):
if arr[j] >= cn... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | def dfs(root):
vis[root] = 1
print(root)
for i in edge[root]:
if not vis[i]:
dfs(i)
return
def main():
t = 1
while t:
t = int(input())
while t:
n = int(input())
a = list(map(int, input().strip().split()))
sum = [0] * n
... | FUNC_DEF ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_DEF ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN ... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
vote = [0] * n
for i in range(n):
fs = 0
for j in range(i - 1, -1, -1):
if fs > a[i]:
break
else:
fs += a[j]
vote[j] += 1
bs ... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR VAR VAR VAR V... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | for i in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
if n >= 2:
y = [2] * n
y[0] = 1
y[n - 1] = 1
for k in range(0, n - 2):
sum = 0
for l in range(k + 1, n - 1):
sum += a[l]
if sum <= a[k]:
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN V... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
l.insert(0, 0)
prefix = [0] * 100010
suffix = [0] * 100010
for i in range(1, n):
total = 0
for j in range(i + 1, n + 1):
total += l[j]
if total > l[i]:
break... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VA... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | for _ in range(int(input())):
N = int(input())
S = list(map(int, input().split()))
t = [0] * N
if N == 1:
print("0")
else:
s = [0] * N
for i in range(0, N):
sum = 0
for j in range(i + 1, N):
if sum <= S[i]:
s[j] += 1... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR V... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | t = int(input())
for i in range(t):
n = int(input())
arr = list(map(int, input().split()))
rev = list(reversed(arr))
vote = [2] * n
vote[0] -= 1
vote[n - 1] -= 1
for j in range(n - 2):
summ = 0
for k in range(j + 2, n):
summ += arr[k - 1]
if summ <= ar... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | def problem3(n, list):
Graph = [0] * n
for i in range(n):
diff = 0
for j in range(i - 1, -1, -1):
if list[i] >= diff:
Graph[j] += 1
diff = diff + list[j]
else:
break
for i in range(n):
diff = 0
for j in r... | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER A... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
re = [0] * n
for i in range(len(a)):
s = 0
for j in range(i + 1, len(a)):
if a[i] >= s:
s += a[j]
re[j] += 1
else:
break
a.revers... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR... |
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to minion N. For each i (1 ≤ i ≤ N), the i-th minion has an influence lev... | test = int(input())
while test > 0:
test -= 1
n = int(input())
l = list(map(int, input().split()))
data = []
curr = 0
for x in l:
curr += x
data += [curr]
count = [0] * n
i = 0
while i < n:
j = i + 1
while l[i] >= data[j - 1] - data[i] and j < n:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR LIST VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN... |
You are given n integers. You need to choose a subset and put the chosen numbers in a beautiful rectangle (rectangular matrix). Each chosen number should occupy one of its rectangle cells, each cell must be filled with exactly one chosen number. Some of the n numbers may not be chosen.
A rectangle (rectangular matrix)... | def play(arr):
n = len(arr)
number2Count = {}
for p in arr:
number2Count[p] = number2Count.get(p, 0) + 1
count2Numbers = {}
maxCnt = 0
for num in number2Count:
cnt = number2Count[num]
if not cnt in count2Numbers:
count2Numbers[cnt] = []
count2Numbers[c... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUM... |
You are given n integers. You need to choose a subset and put the chosen numbers in a beautiful rectangle (rectangular matrix). Each chosen number should occupy one of its rectangle cells, each cell must be filled with exactly one chosen number. Some of the n numbers may not be chosen.
A rectangle (rectangular matrix)... | n = int(input())
arr = list(map(int, input().split()))
d = {}
for i in arr:
d[i] = d.get(i, 0) + 1
d2 = {}
for k, v in d.items():
d2.setdefault(v, []).append(k)
s = n
prev = 0
ansp = ansq = anss = 0
for p in range(n, 0, -1):
q = s // p
if p <= q and q * p > anss:
anss = q * p
ansq = q
... | 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 FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL FUNC_CALL VAR VAR LIST VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ... |
You are given n integers. You need to choose a subset and put the chosen numbers in a beautiful rectangle (rectangular matrix). Each chosen number should occupy one of its rectangle cells, each cell must be filled with exactly one chosen number. Some of the n numbers may not be chosen.
A rectangle (rectangular matrix)... | n = int(input())
l = list(map(int, input().split()))
if n == 1:
print(1)
print(1, 1)
print(l[0])
else:
d = {}
for i in l:
d[i] = 0
for i in l:
d[i] += 1
equal = [0] * (n + 1)
for i in d:
equal[d[i]] += 1
atmost = [0] * (n + 1)
atmost[0] = equal[0]
for ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_... |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, A, N):
d = dict()
for element in A:
if element in d:
d[element] += 1
else:
d[element] = d.get(element, 0) + 1
for element in d:
if d[element] > N / 2:
return element... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR BIN_OP VAR NUMBER RETURN VAR RETURN NUMBER |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, A, N):
A.sort()
mid = A[N // 2]
if A.count(mid) > N // 2:
return mid
else:
return -1 | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN VAR RETURN NUMBER |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, A, N):
A.sort()
x = 0
x1 = A[0]
for i in A:
if i == x1:
x = x + 1
if x > N // 2:
return i
else:
x1 = i
x = 1
return -1 | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR ASSIGN VAR NUMBER RETURN NUMBER |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def findCandidate(self, A):
maj_index = 0
count = 1
for i in range(len(A)):
if A[maj_index] == A[i]:
count += 1
else:
count -= 1
if count == 0:
maj_index = i
count = 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR V... |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, A, N):
if N == 1:
return A[0]
A.sort()
count = 1
curr = A[0]
for idx in range(1, N):
if A[idx] == curr:
count += 1
else:
count = 1
curr = A[idx]
... | CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR BIN_OP VAR NUMBER RETURN VAR RETURN NUMBER |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, A, N):
elem = A[0]
count = 1
maxCount = 0
for idx in range(1, N):
if A[idx] == elem:
count += 1
elif count == 0:
elem = A[idx]
count = 1
else:
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR BIN_OP VAR NUMBER VAR NUMBER |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, A, N):
c = {}
for i in A:
c[i] = c.get(i, 0) + 1
if c[i] > N / 2:
return i
return -1 | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR BIN_OP VAR NUMBER RETURN VAR RETURN NUMBER |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, A, N):
element = None
counter = 0
for i in range(N):
if counter == 0:
counter = 1
element = A[i]
elif element == A[i]:
counter += 1
else:
counter -= ... | CLASS_DEF FUNC_DEF ASSIGN VAR NONE ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER RETURN VAR RETURN NUMBER |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, A, N):
elem = 0
count = 0
maxcount = 0
for ele in A:
if count == 0:
elem = ele
if ele == elem:
count += 1
else:
count -= 1
for val in A:
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR BIN_OP VAR NUMBER VAR NUMBER |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, A, N):
cnt = 0
cur = 0
for i in range(N):
if cnt == 0:
cur = A[i]
cnt = 1
elif cur == A[i]:
cnt += 1
else:
cnt -= 1
c = 0
for el in A... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR BIN_OP VAR NUMBER VAR NUMBER |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, A, N):
lis = {}
x = N // 2
for i in A:
if i in lis:
lis[i] = lis[i] + 1
else:
lis[i] = 1
if lis[i] > x:
return i
return -1 | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR BIN_OP VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR RETURN VAR RETURN NUMBER |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, A, N):
dic = {}
ans = -1
maxi = 0
if N == 1:
return A[0]
for ele in A:
if ele in dic:
dic[ele] += 1
else:
dic[ele] = 1
for x in dic:
if dic[x] > ... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER RETURN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER RETURN NUMBER RETURN VAR |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, A, n):
dic = {}
ans = -1
for i in A:
if i not in dic:
dic[i] = 1
else:
dic[i] += 1
for key, value in dic.items():
if value > n // 2:
ans = key
return... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def find_majority_candidate(self, A, N):
maj_index = 0
count = 1
for i in range(len(A)):
if A[maj_index] == A[i]:
count += 1
else:
count -= 1
if count == 0:
maj_index = i
coun... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR RET... |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, A, N):
mapp = {}
mid = N // 2
for i in range(N):
if A[i] in mapp:
mapp[A[i]] += 1
else:
mapp[A[i]] = 1
for k in mapp.keys():
if mapp[k] > mid:
return k
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR VAR RETURN VAR RETURN NUMBER |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, A, N):
d = {}
for e in A:
if e in d:
d[e] = d[e] + 1
else:
d[e] = 1
if d[e] > N / 2:
return e
return -1 | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER RETURN VAR RETURN NUMBER |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, A, N):
flag = True
re = N // 2
dict = {}
if N == 1:
return A[0]
else:
for i in A:
if i in dict:
dict[i] += 1
else:
dict[i] = 0
fo... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR DICT IF VAR NUMBER RETURN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER RETURN VAR IF VAR NUMBER RETURN NUMBER |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, A, N):
d = {}
ans = -1
for i in range(N):
if A[i] not in d:
d[A[i]] = 1
else:
d[A[i]] = d[A[i]] + 1
for k in d:
if d[k] > N / 2:
ans = k
brea... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER FOR VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, A, N):
d = {}
f = 0
ans = 0
for ele in A:
if ele in d.keys():
d[ele] += 1
else:
d[ele] = 1
for keys in d.keys():
if d[keys] > N / 2:
ans = keys
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER RETURN VAR RETURN NUMBER |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, A, N):
if N == 1:
return A[0]
else:
my_list = A
size = N / 2
element_count = {}
for element in my_list:
if element in element_count:
element_count[element] += 1
... | CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR VAR RETURN VAR |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, A, N):
A.sort()
n = N // 2
i = 0
while i < N:
j = i
if i + 1 < N and A[i] == A[i + 1]:
while i + 1 < N and A[i] == A[i + 1]:
i = i + 1
k = i
if k - j + 1 > n... | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR RETURN VAR VA... |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, A, N):
temp = N // 2
hashed = {}
for i in A:
hashed[i] = 1 + hashed.get(i, 0)
for i in hashed:
if hashed[i] > temp:
return i
return -1 | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR RETURN VAR RETURN NUMBER |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, A, N):
mp = {}
for i in range(N):
if A[i] in mp:
mp[A[i]] += 1
else:
mp[A[i]] = 1
for i in mp.keys():
if mp[i] > N // 2:
return i
return -1 | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR BIN_OP VAR NUMBER RETURN VAR RETURN NUMBER |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, A, N):
count = {}
res, maxcount = -1, 0
for n in A:
count[n] = 1 + count.get(n, 0)
res = n if count[n] > maxcount else res
maxcount = max(maxcount, count[n])
return res if maxcount > N / 2 else -1 | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR BIN_OP VAR NUMBER VAR NUMBER |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, arr, n):
d = {}
m = -1
ans = -1
if n == 1:
return arr[0]
for i in arr:
if i not in d:
d[i] = 1
else:
d[i] += 1
for i, j in d.items():
if j > n //... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER RETURN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER RETURN VAR RETURN NUMBER |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, A, N):
m1, c1 = None, 0
for i in A:
if i == m1:
c1 += 1
elif c1 == 0:
m1 = i
c1 = 1
else:
c1 -= 1
ans = -1
if A.count(m1) > N / 2:
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NONE NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, A, N):
dict1 = {}
maj = -1
majVal = -1
if N == 1:
return A[0]
for i in range(N):
if A[i] in dict1:
dict1[A[i]] += 1
else:
dict1[A[i]] = 1
for key in dict1:
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER RETURN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER RETURN VAR RETURN NUMBER |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, array, n):
result, count = array[0], 1
for data in array[1:]:
count = count + 1 if data == result else count - 1
if count == 0:
result, count = data, 1
count = 0
for data in array:
if data ... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER FOR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER RETURN VAR |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, A, N):
c = 0
majr = 0
for i in range(0, N):
if c == 0:
majr = i
c = 1
elif A[majr] == A[i]:
c = c + 1
else:
c = c - 1
C = 0
for i in ... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF... |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, A, N):
d = {}
for i in range(N):
if N == 1:
return A[0]
if A[i] not in d:
d[A[i]] = 1
else:
d[A[i]] += 1
if d[A[i]] > N / 2 and d[A[i]] != 1:
ret... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER RETURN VAR VAR RETURN NUMBER |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, A, N):
count = 1
i = 1
candidate = A[0]
while i < len(A):
if candidate == A[i]:
count += 1
else:
count -= 1
if count == 0:
candidate = A[i]
c... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER RETURN VAR RETURN NUMBER |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, A, N):
max = A[0]
occur = 1
for i in range(1, len(A)):
if occur == 0:
occur += 1
max = A[i]
elif A[i] == max:
occur += 1
else:
occur -= 1
if ... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN VAR RETURN NUMBER |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, A, N):
dic = {}
for i in A:
dic[i] = 1 + dic.get(i, 0)
for k, v in dic.items():
if v > N // 2:
return k
return -1 | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER RETURN VAR RETURN NUMBER |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def possible(self, l, n):
val = l[0]
cnt = 1
for i in range(1, n):
if l[i] == val:
cnt += 1
else:
cnt -= 1
if cnt == 0:
val = l[i]
cnt = 1
return val
def majority... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, A, N):
count = 1
maj_ele = A[0]
for i in range(1, N):
num = A[i]
if num == maj_ele:
count += 1
else:
count -= 1
if count == 0:
count = 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN VAR RETURN NUMBER |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, A, N):
if N == 1:
return A[0]
Map = {}
for ele in A:
if ele in Map:
Map[ele] += 1
if Map[ele] > N / 2:
return ele
else:
Map[ele] = 1
retu... | CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR NUMBER RETURN NUMBER |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, A, N):
c = N / 2
dict = {}
if N == 1:
return A[0]
for x in A:
if x not in dict:
dict[x] = 1
elif x in dict:
dict[x] += 1
if dict[x] > c:
... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR DICT IF VAR NUMBER RETURN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR RETURN VAR RETURN NUMBER |
Given an array A of N elements. Find the majority element in the array. A majority element in an array A of size N is an element that appears more than N/2 times in the array.
Example 1:
Input:
N = 3
A[] = {1,2,3}
Output:
-1
Explanation:
Since, each element in
{1,2,3} appears only once so there
is no majority ele... | class Solution:
def majorityElement(self, A, N):
half = N // 2
hash = {}
for ele in A:
if ele not in hash:
hash[ele] = 1
else:
hash[ele] += 1
for k, v in hash.items():
if v > half:
return k
r... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR VAR RETURN VAR RETURN NUMBER |
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands.
A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after on... | class Node:
def __init__(self, value, parent):
self.value = value
self.parent = parent
def solve(n, A):
tree = Node(int(A[0]), None)
ans = [A[0]]
node = tree
for a in A[1:]:
a_i = int(a)
if a == "1":
new_node = Node(a_i, node)
node = new_nod... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NONE ASSIGN VAR LIST VAR NUMBER ASSIGN VAR VAR FOR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR WHILE NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_C... |
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands.
A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after on... | def f(a):
prev = a[0]
st = [a[0]]
print(a[0])
for i in a[1:]:
if i == 1:
st.append(i)
print(".".join(list(map(str, st))))
continue
else:
t = None
for ind in range(0, len(st)):
if i - st[ind] == 1:
... | FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR LIST VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NONE FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR V... |
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands.
A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after on... | for _ in range(int(input())):
n = int(input())
x = int(input())
l = [1]
print(1)
for i in range(1, n):
x = int(input())
if x == 1:
l.append(1)
else:
j = len(l) - 1
while j >= 0:
if x == l[j] + 1:
l[j] += ... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR... |
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands.
A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after on... | for _ in range(int(input())):
n = int(input())
b = [(0) for i in range(1007)]
p = -1
for i in range(n):
a = int(input())
if a > 1:
while b[p] != a - 1:
p -= 1
p -= 1
p += 1
b[p] = a
print(*b[: p + 1], sep=".") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR EXPR FU... |
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands.
A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after on... | for _ in range(int(input())):
n = int(input())
l = []
for i in range(n):
l += [int(input())]
a = [[l[0]]]
for i in range(1, n):
if l[i] == 1:
a += [a[-1] + [1]]
else:
j = len(a[-1]) - 1
while a[-1][j] + 1 != l[i]:
j -= 1
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR LIST FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR LIST BIN_OP VAR NUMBER LIST NUMBER ASSIGN VAR BIN_OP FUNC_CALL VA... |
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands.
A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after on... | def findr(a, i, cur):
for k in range(cur, -1, -1):
if a[k] == i:
return k
t = int(input())
for _ in range(t):
n = int(input())
a = []
b = [[]]
urov_last_num = [(0) for __ in range(1000)]
urov_strings = [""]
for k in range(n):
a.append(int(input()))
print("1"... | FUNC_DEF FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CA... |
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands.
A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after on... | import sys
def Ints():
return map(int, sys.stdin.readline().strip().split())
def Strs():
return map(str, sys.stdin.readline().strip().split())
def Array():
return list(map(int, sys.stdin.readline().strip().split()))
def Str():
return sys.stdin.readline().strip()
def Int():
return int(sys.s... | IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR F... |
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands.
A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after on... | t = int(input())
for _ in range(t):
n = int(input())
arr = ["", "1"]
a = int(input())
print(1)
for __ in range(n - 1):
a = int(input())
if a == 1:
print(arr[-1] + ".1")
arr.append(arr[-1] + ".1")
elif int(arr[-1][-1]) + 1 == a:
arr[-1] = ar... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VA... |
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands.
A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after on... | final = []
t = int(input())
for z in range(t):
n = int(input())
ls = []
for j in range(n):
inp = int(input())
if len(ls) == 0:
ls.append(inp)
elif inp == ls[-1] + 1:
ls[-1] = inp
activels = False
elif inp == 1:
ls.append(1)
... | ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR NUM... |
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands.
A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after on... | for _ in range(int(input())):
n = int(input())
li = [int(input()) for _ in range(n)]
st = []
for n in li:
if n == 1:
st.append(1)
else:
while st[-1] != n - 1:
st.pop()
st.append(st.pop() + 1)
print(".".join(map(str, st))) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER E... |
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands.
A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after on... | def pr(v):
s = ""
for j in range(len(v)):
s += v[j] + "."
print(s[:-1])
t = int(input())
while t:
t -= 1
n = int(input())
ans, i = [], 0
while i < n:
temp = int(input())
if temp == 1:
ans.append(str(temp))
pr(ans)
elif int(ans[-1]) ==... | FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR LIST NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR... |
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands.
A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after on... | for _ in range(int(input())):
n = int(input())
s = []
lens = 0
for __ in range(n):
x = int(input())
if x == 1:
s.append(x)
lens += 1
print(".".join([str(x) for x in s]))
else:
while 1:
if lens == 0:
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR WHILE NUMBER IF VAR NU... |
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands.
A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after on... | for _ in range(int(input())):
x = int(input())
Ans = []
s = []
for i in range(x):
a = int(input())
if a == 1:
s.append(1)
Ans.append(list(s))
else:
while s[-1] != a - 1:
s.pop()
s[-1] += 1
Ans.append(list... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR... |
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands.
A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after on... | t = int(input())
def print_ol():
n = int(input())
levels = []
for i in range(n):
x = int(input())
if x == 1:
levels.append(1)
else:
while levels[-1] + 1 != x:
levels.pop()
levels[-1] += 1
print(".".join(list(map(str, level... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC... |
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands.
A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after on... | import sys
T = int(sys.stdin.readline().strip())
for t in range(0, T):
n = int(sys.stdin.readline().strip())
x = int(sys.stdin.readline().strip())
ans = [[x]]
for i in range(0, n - 1):
x = int(sys.stdin.readline().strip())
ans.append(ans[-1][:])
if x == 1:
ans[-1].ap... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CA... |
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands.
A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after on... | t = int(input())
for _ in range(t):
n = int(input())
stack = []
arr = []
for i in range(n):
k = int(input())
if k == 1:
stack.append(k)
arr.append("1")
else:
while stack[-1] != k - 1:
stack.pop()
arr.pop()
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING WHILE VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EX... |
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands.
A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after on... | for _ in range(int(input())):
N = int(input())
S = []
for _ in range(N):
x = int(input())
if x == 1:
S.append(x)
else:
while S and S[-1] != x - 1:
S.pop()
assert S
S[-1] = x
print(".".join(map(str, S))) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL ... |
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands.
A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after on... | for _ in range(int(input())):
size = int(input())
nums = []
index = [1]
for i in range(size):
nums.append(int(input()))
index.append(0)
lvl = 1
print(1)
for i in range(1, size):
if nums[i] == 1:
lvl += 1
index[lvl - 1] = 1
elif nums[i] ... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBE... |
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands.
A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after on... | for _ in range(int(input())):
n = int(input())
ar = [0]
for i in range(n):
x = int(input())
pos = -1
for j in range(len(ar) - 1, 0, -1):
if ar[j] == x - 1:
pos = j
break
if pos != -1:
for j in range(len(ar) - pos):
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER... |
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands.
A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after on... | t = int(input())
while int(t) > 0:
n = int(input())
v = []
while n > 0:
char = int(input())
if len(v) == 0 or char == 1:
v.append(char)
else:
for i in range(len(v) - 1, -1, -1):
if char == v[i] + 1:
v[i] = char
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR BI... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.