description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved.
There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a... | for _ in range(int(input())):
n = int(input())
a = input()
b = input()
operations = []
for i in range(n - 1):
if a[i] != a[i + 1]:
operations.append(i + 1)
if a[-1] == "1":
operations.append(n)
if b[-1] == "1":
operations.append(n)
for i in reversed(ra... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR NUMB... |
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved.
There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a... | import sys
input = sys.stdin.readline
T = int(input())
for t in range(T):
N = int(input())
A = input()[:-1]
B = input()[:-1]
answer = []
el0 = A[0]
for i in range(N - 1, -1, -1):
if el0 == B[i]:
answer.append(1)
answer.append(i + 1)
if i == N - 1:
... | IMPORT ASSIGN VAR 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 FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMB... |
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved.
There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a... | import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
n = int(input())
s = [int(item) for item in list(input().rstrip())]
t = [int(item) for item in list(input().rstrip())]
srev = []
for item in s:
srev.append(1 - item)
ans = []
state = 1
for_idx = n - 1
... | IMPORT ASSIGN VAR 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 FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_O... |
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved.
There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a... | import sys
sys.setrecursionlimit(10**5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number):
return [... | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC... |
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved.
There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a... | import sys
def solve(ls1, ls2, debug=0):
n = len(ls1)
result = []
for i in range(n):
if i % 2:
j = -1 - i // 2
x = ls1[j] ^ 1
else:
j = i // 2
x = ls1[j]
y = ls2[-i - 1]
if debug:
print(f"i: {i}, j: {j}, x: {x}, y:... | IMPORT FUNC_DEF NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING VAR STRING VAR ... |
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved.
There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a... | import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().strip()))
b = list(map(int, input().strip()))
ans1, ans2 = [], []
if a.count(1) > n // 2:
for i in range(n):
a[i] = 1 * (a[i] == 0)
a.reverse()
an... | IMPORT ASSIGN VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST LIST IF FUNC_CALL VAR NUMBER BIN_OP VAR ... |
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved.
There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a... | for _ in range(int(input())):
n = int(input())
a = input()
b = input()
i = 1
s = a[0]
ans = []
while i < n:
if a[i] == s[-1]:
i += 1
continue
elif a[i] == "1" and s[-1] == "0":
s = "1"
ans.append(i)
else:
s =... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER STRING ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR A... |
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved.
There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a... | for _ in range(int(input())):
n = int(input())
s = input()
b = input()
A = []
for i in range(n - 1):
if s[i] != s[i + 1]:
A.append(i + 1)
if s[-1] == "1":
A.append(n)
A1 = []
for i in range(n - 1):
if b[i] != b[i + 1]:
A1.append(i + 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 ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR ... |
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved.
There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a... | t = int(input())
for _ in range(t):
n = int(input())
a = input()
b = input()
ans = []
cur = a[0]
inv = 0
in0 = 0
arr = [0] * n
ar1 = [i for i in range(1, (n + 1) // 2 + 1)]
ar2 = [i for i in range(n, (n + 1) // 2, -1)]
na = []
for i in range(len(ar2)):
na.append(a... | 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 ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_... |
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved.
There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a... | for tt in range(int(input())):
n = int(input())
b = input()
a = input()
ans = []
for i in range(n - 1):
if b[i] != b[i + 1]:
ans.append(i + 1)
cur = int(b[-1])
for i in range(n - 1, -1, -1):
if cur != int(a[i]):
ans.append(i + 1)
cur ^= 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 ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL V... |
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved.
There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a... | import sys
LI = lambda: list(map(int, sys.stdin.readline().strip("\n").split()))
MI = lambda: map(int, sys.stdin.readline().strip("\n").split())
SI = lambda: sys.stdin.readline().strip("\n")
II = lambda: int(sys.stdin.readline().strip("\n"))
for _ in range(II()):
n, a, b = II(), SI() + "0", SI() + "0"
one, two... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_C... |
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved.
There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a... | for _ in range(int(input())):
n = int(input())
a = input()
b = input()
ans = []
arr = []
for i in range(n - 1):
if a[i] != a[i + 1]:
ans.append(i + 1)
for i in range(n - 1):
if b[i] != b[i + 1]:
arr.append(i + 1)
if a[n - 1] != b[n - 1]:
an... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER... |
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved.
There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a... | for _ in range(int(input())):
n = int(input())
a = input()
b = input()
ans = []
sign = -1
for ansi in range(n, 0, -1):
if (a[(n + ansi * sign) // 2] == b[ansi - 1]) ^ (sign > 0):
ans.append(1)
ans.append(ansi)
sign = -sign
print(len(ans), *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 ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR N... |
This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved.
There are two binary strings $a$ and $b$ of length $n$ (a binary string is a string consisting of symbols $0$ a... | import sys
inp = sys.stdin.read().split()
ii = 0
t = int(inp[ii])
ii += 1
for _ in range(t):
toprint = []
n = int(inp[ii])
ii += 1
c = list(map(int, inp[ii]))
ii += 1
b = list(map(int, inp[ii]))
ii += 1
count = 0
for i in range(n - 1, -1, -1):
if count % 2 == 0:
... | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN... |
You are visiting a farm that has a single row of fruit trees arranged from left to right.The trees are represented by an integer array fruits of size N, where fruits[i] is the type of fruit the ith tree produces.
You want to collect as much fruit as possible.However,the owner has some strict rules that you must follow... | class Solution:
def sumSubarrayMins(self, N, fruits):
i, j, ans = 0, 0, 0
state = {}
while j < N:
state[fruits[j]] = 1 + state.get(fruits[j], 0)
while len(state) > 2:
state[fruits[i]] = -1 + state.get(fruits[i])
if state[fruits[i]] == ... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR DICT WHILE VAR VAR ASSIGN VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VA... |
You are visiting a farm that has a single row of fruit trees arranged from left to right.The trees are represented by an integer array fruits of size N, where fruits[i] is the type of fruit the ith tree produces.
You want to collect as much fruit as possible.However,the owner has some strict rules that you must follow... | class Solution:
def sumSubarrayMins(self, N, fruits):
start, end, count, ans = 0, 0, 0, 0
cnt = [0] * (max(fruits) + 1)
while end < N:
if cnt[fruits[end]] == 0:
count += 1
cnt[fruits[end]] += 1
end += 1
while start < end and co... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VA... |
You are visiting a farm that has a single row of fruit trees arranged from left to right.The trees are represented by an integer array fruits of size N, where fruits[i] is the type of fruit the ith tree produces.
You want to collect as much fruit as possible.However,the owner has some strict rules that you must follow... | class Solution:
def sumSubarrayMins(self, N, fruits):
dic = {}
cnt = 0
ans = 0
j = 0
for i in range(N):
el = fruits[i]
if el not in dic:
dic[el] = 1
cnt += 1
while len(dic) > 2 and j < i:
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER AS... |
You are visiting a farm that has a single row of fruit trees arranged from left to right.The trees are represented by an integer array fruits of size N, where fruits[i] is the type of fruit the ith tree produces.
You want to collect as much fruit as possible.However,the owner has some strict rules that you must follow... | class Solution:
def sumSubarrayMins(self, n, fruits):
hashmap = {}
l, r = 0, 0
res = 0
while r < n:
while len(hashmap) >= 2 and fruits[r] not in hashmap:
hashmap[fruits[l]] -= 1
if hashmap[fruits[l]] == 0:
del hashmap[f... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMB... |
You are visiting a farm that has a single row of fruit trees arranged from left to right.The trees are represented by an integer array fruits of size N, where fruits[i] is the type of fruit the ith tree produces.
You want to collect as much fruit as possible.However,the owner has some strict rules that you must follow... | class Solution:
def sumSubarrayMins(self, N, fruits):
i, j = 0, 0
d = {}
maxi = 1
while j < N:
d[fruits[j]] = d.get(fruits[j], 0) + 1
if len(d) <= 2:
maxi = max(maxi, j - i + 1)
j += 1
else:
while le... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR ... |
You are visiting a farm that has a single row of fruit trees arranged from left to right.The trees are represented by an integer array fruits of size N, where fruits[i] is the type of fruit the ith tree produces.
You want to collect as much fruit as possible.However,the owner has some strict rules that you must follow... | class Solution:
def sumSubarrayMins(self, N, fruits):
fruitsCnt = dict()
maxFruits = 0
startIdx = 0
for endIdx in range(len(fruits)):
if fruits[endIdx] in fruitsCnt:
fruitsCnt[fruits[endIdx]] += 1
else:
fruitsCnt[fruits[endIdx]... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER WHILE VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NONE VAR NUMBER ASSIGN VAR FUNC_C... |
You are visiting a farm that has a single row of fruit trees arranged from left to right.The trees are represented by an integer array fruits of size N, where fruits[i] is the type of fruit the ith tree produces.
You want to collect as much fruit as possible.However,the owner has some strict rules that you must follow... | class Solution:
def sumSubarrayMins(self, N, fruits):
res = 0
r = 0
d = dict()
for i in range(N):
d[fruits[i]] = d.get(fruits[i], 0) + 1
while len(d) > 2:
d[fruits[r]] = d.get(fruits[r], 0) - 1
if d[fruits[r]] == 0:
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF FUNC_CALL V... |
You are visiting a farm that has a single row of fruit trees arranged from left to right.The trees are represented by an integer array fruits of size N, where fruits[i] is the type of fruit the ith tree produces.
You want to collect as much fruit as possible.However,the owner has some strict rules that you must follow... | class Solution:
def sumSubarrayMins(self, N, fruits):
k = 2
type = {}
i = 0
j = 0
max_fruits = 0
while j < N:
fruit = fruits[j]
type[fruit] = type.get(fruit, 0) + 1
if len(type) > k:
max_fruits = max(max_fruits, j -... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR... |
You are visiting a farm that has a single row of fruit trees arranged from left to right.The trees are represented by an integer array fruits of size N, where fruits[i] is the type of fruit the ith tree produces.
You want to collect as much fruit as possible.However,the owner has some strict rules that you must follow... | class Solution:
def sumSubarrayMins(self, N, fruits):
basket = {}
max_picked = 0
left = 0
for right in range(len(fruits)):
basket[fruits[right]] = basket.get(fruits[right], 0) + 1
while len(basket) > 2:
basket[fruits[left]] -= 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR N... |
You are visiting a farm that has a single row of fruit trees arranged from left to right.The trees are represented by an integer array fruits of size N, where fruits[i] is the type of fruit the ith tree produces.
You want to collect as much fruit as possible.However,the owner has some strict rules that you must follow... | class Solution:
def sumSubarrayMins(self, N, fruits):
first = fruits[0]
second = -1
i = 0
j = 1
ans = 1
while j < N:
if fruits[j] != first and fruits[j] != second:
if second == -1:
second = fruits[j]
els... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSI... |
You are visiting a farm that has a single row of fruit trees arranged from left to right.The trees are represented by an integer array fruits of size N, where fruits[i] is the type of fruit the ith tree produces.
You want to collect as much fruit as possible.However,the owner has some strict rules that you must follow... | class Solution:
def sumSubarrayMins(self, N, fruits):
pt1, pt2 = 0, 0
hash_map = {}
ct = 0
no_fruits = 0
max_fruits = 0
while pt1 <= pt2 and pt2 < N:
if fruits[pt2] in hash_map:
hash_map[fruits[pt2]] += 1
else:
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NU... |
You are visiting a farm that has a single row of fruit trees arranged from left to right.The trees are represented by an integer array fruits of size N, where fruits[i] is the type of fruit the ith tree produces.
You want to collect as much fruit as possible.However,the owner has some strict rules that you must follow... | class Solution:
def sumSubarrayMins(self, N, fruits):
fp, lp, mp = 0, 0, {}
ans = 0
while lp < N:
if fruits[lp] not in mp and len(mp) == 2:
while len(mp) == 2 and fp < lp:
mp[fruits[fp]] -= 1
if mp[fruits[fp]] == 0:
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER DICT ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FU... |
You are visiting a farm that has a single row of fruit trees arranged from left to right.The trees are represented by an integer array fruits of size N, where fruits[i] is the type of fruit the ith tree produces.
You want to collect as much fruit as possible.However,the owner has some strict rules that you must follow... | class Solution:
def sumSubarrayMins(self, n, fruits):
hm = {}
l = 0
r = 0
k = 2
ans = 0
while r < n:
if fruits[r] in hm:
hm[fruits[r]] += 1
else:
hm[fruits[r]] = 1
if len(hm) > k:
hm[... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUM... |
You are visiting a farm that has a single row of fruit trees arranged from left to right.The trees are represented by an integer array fruits of size N, where fruits[i] is the type of fruit the ith tree produces.
You want to collect as much fruit as possible.However,the owner has some strict rules that you must follow... | class Solution:
def sumSubarrayMins(self, n, a):
d = {}
f = 0
for i in range(n):
if len(d) == 2:
f = 1
break
elif a[i] not in d.keys():
d[a[i]] = 1
else:
d[a[i]] += 1
if f == 0:
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR FUN... |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
averages = []
first = True
sum_avg = 0
for i in range(len(arr) - (k - 1)):
if first:
for j in range(k):
sum_avg += arr[i + j]
firs... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR V... |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
threshold *= k
window = 0
ans = 0
for r, num in enumerate(arr):
window += num
if r >= k:
window -= arr[r - k]
if r >= k - 1 and window >= thre... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER RETURN VAR VAR |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, a: List[int], k: int, threshold: int) -> int:
lo, sum_of_win, cnt, target = -1, 0, 0, k * threshold
for hi, v in enumerate(a):
sum_of_win += v
if hi - lo == k:
if sum_of_win >= target:
cnt += 1
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER BIN_OP VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR RETURN VAR VAR |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
res = 0
s = sum(arr[: k - 1])
t = threshold * k
for i in range(k - 1, len(arr)):
s += arr[i]
if s >= t:
res += 1
s -= arr[i + 1 - k]
r... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN VAR VAR |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
goal = k * threshold
cSums = [(0) for i in arr]
c = 0
for i in range(len(arr)):
if i == 0:
cSums[0] = arr[0]
else:
cSums[i] = cSums[i - 1]... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR VAR IF BIN_OP VAR VAR ... |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
minVal = k * threshold
beg = 0
end = k - 1
total = 0
currSum = 0
for i in range(beg, end + 1):
currSum += arr[i]
while end < len(arr):
if beg != 0... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR WHILE VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR NUMB... |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
if len(arr) < k:
return 0
prevAverage = 0
counter = 0
for i in range(len(arr) - k + 1):
if i == 0:
average = sum(arr[i : i + k]) / k
else:
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR... |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
sm = threshold * k
ct = 0
tot = 0
for i in range(len(arr)):
tot += arr[i]
if i < k - 1:
continue
if i > k - 1:
tot -= arr[i - ... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER RETURN VAR VAR |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
s = l = 0
for r in range(k):
s += arr[r]
ans = 0
while r < len(arr) - 1:
if s >= threshold * k:
ans += 1
s -= arr[l]
l += 1
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR VAR |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
if len(arr) < k:
return None
k_sum = sum([arr[i] for i in range(0, k)])
count = 0
p1, p2 = 0, k
if k_sum / k >= threshold:
count += 1
while p2 < len(arr):... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR RETURN NONE ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR... |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
l = 0
r = k - 1
total = sum(arr[0:k])
if total / k >= threshold:
count = 1
else:
count = 0
while r < len(arr) - 1:
total -= arr[l]
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR VAR |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
l, r = 0, k - 1
temp = 0
for i in range(l, r + 1):
temp += arr[i]
res = 0 if temp < k * threshold else 1
while r < len(arr) - 1:
temp += arr[r + 1] - arr[l]
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR VAR ... |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
l, r = 0, k - 1
res = 0
s = sum(arr[:k])
t = threshold * k
while r < len(arr):
if s >= t:
res += 1
if r + 1 < len(arr):
s = s - ar... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBE... |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
target = k * threshold
s, ans = 0, 0
for i, num in enumerate(arr):
if i < k:
s += num
continue
if s >= target:
ans += 1
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR VAR |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
tmp = [sum(arr[:k])]
for i in range(k, len(arr)):
temp = tmp[-1]
temp = temp - arr[i - k] + arr[i]
tmp.append(temp)
print(tmp)
count = 0
for el in tmp... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR LIST FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR VAR |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
cur = 0
res = 0
for i in range(k):
cur += arr[i]
if cur / k >= threshold:
res += 1
for i in range(k, len(arr)):
cur = cur + arr[i] - arr[i - k]
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR VAR |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
temp = sum(arr[:k])
count = 0 if temp / k < threshold else 1
for i in range(k, len(arr)):
temp = temp - arr[i - k] + arr[i]
if temp / k >= threshold:
count += 1
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR VAR |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
n = len(arr)
a = [0] * (n + 1)
for i in range(1, n + 1):
a[i] = arr[i - 1] + a[i - 1]
cnt = 0
for i in range(k, n + 1):
res = a[i] - a[i - k]
if res /... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN... |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
if len(arr) < k:
return 0
bar = k * threshold
total = 0
window = sum(arr[:k])
if window >= bar:
total += 1
for i in range(k, len(arr)):
window... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR VAR |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def __init__(self):
self.counter = 0
self.threshold = 0
self.k = 0
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
self.k = k
self.threshold = threshold
interval = sum(arr[:k])
self._count_if_slice_sum_passes_thre... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR EXPR... |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
if len(arr) < k:
return 0
store = [0] * len(arr)
i = 0
j = 0
ans = 0
while i < len(arr):
if i - j + 1 == k:
if j == 0:
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR... |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
rep = 0
target = k * threshold
cur = sum(arr[:k])
if cur >= target:
rep += 1
l, r = 0, k
while r < len(arr):
cur -= arr[l]
cur += arr[r]
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
s = 0
ret = 0
for i, num in enumerate(arr):
if i - k < 0:
s += num
if s >= threshold * k and i == k - 1:
ret += 1
prin... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR IF VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR VAR |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
start = 0
end = k
count = 0
sumInit = sum(arr[start:end])
if sumInit / k >= threshold:
count += 1
while end < len(arr):
sumInit = sumInit - arr[start] + a... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
s = threshold * k
s1 = sum(arr[:k])
n = len(arr)
c = 0
if s1 >= s:
c += 1
for i in range(k, n):
s1 -= arr[i - k]
s1 += arr[i]
if s... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR VAR |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
ans, sm = 0, 0
q = deque()
for v in arr:
sm += v
q.append(v)
if len(q) > k:
sm -= q.popleft()
if len(q) == k:
ans += sm / ... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR RETURN VAR VAR |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
start = 0
count = 0
threshold = threshold * k
avg = sum(arr[start:k])
i = k
while i <= len(arr):
if start != 0:
avg = avg - arr[start - 1] + arr[i - 1... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR V... |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
size = len(arr)
avg = sum(arr[:k]) / k
count = 1 if avg >= threshold else 0
end = k
while end < size:
prevVal = arr[end - k] / k
nextVal = arr[end] / k
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER NUMBER VAR NUMBER RETURN VAR VAR |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr, k, threshold) -> int:
s = 0
sub = arr[0:k]
subSum = sum(sub)
avg = subSum / k
if avg >= threshold:
s += 1
i = k
j = 0
while i < len(arr):
subSum += arr[i]
subSum -= arr[... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER RETURN VAR VAR |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, a: List[int], k: int, threshold: int) -> int:
prefixSum = [0]
for i in a:
prefixSum.append(i + prefixSum[-1])
return sum(
prefixSum[i + k] - prefixSum[i] >= k * threshold
for i in range(len(a) - k + 1)
) | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
start = 0
s = 0
count = 0
for end in range(len(arr)):
s = s + arr[end]
if end - start + 1 == k:
if s / k >= threshold:
count += 1
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER RETURN VAR VAR |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
ans = 0
n = len(arr)
start = 0
end = 0
presum = [0]
for num in arr:
presum.append(presum[-1] + num)
for i in range(0, n - k + 1):
if (presum[i + k... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER RETUR... |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
answer = 0
initial_sum = sum(arr[:k])
for i in range(len(arr) - k + 1):
if i == 0:
if initial_sum / k >= threshold:
answer += 1
else:
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER RETUR... |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
if not arr or len(arr) < k:
return 0
summ = [0]
res = 0
for p, v in enumerate(arr):
i = p + 1
summ.append(summ[p] + v)
if i - k >= 0:
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER RETURN VAR VAR |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
threshold *= k
n = len(arr)
l = 0
tmp_sum = 0
count = 0
for i in range(k):
tmp_sum += arr[i]
if tmp_sum >= threshold:
count += 1
for l in ... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR VAR |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
answer = 0
avg = average(arr[0:k])
prev_el = arr[0]
if avg >= threshold:
answer += 1
for i in range(k, len(arr)):
new_avg = (avg * k - prev_el + arr[i]) / k
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NU... |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
i = 0
j = i + k
s = sum(arr[i:j])
c = 0
while j <= len(arr):
if s // k >= threshold:
c += 1
s -= arr[i]
if j < len(arr):
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR VAR |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
l = len(arr)
ans = 0
x = 0
running_sum = sum(arr[0:k])
if running_sum / k >= threshold:
ans += 1
while k + x < l:
running_sum += arr[k + x] - arr[x]
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR VAR |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
total = sum(arr[:k])
result = 0
for i in range(k, len(arr) + 1):
avg = total / k
if avg >= threshold:
result += 1
if i < len(arr):
lef... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR RETURN VAR VAR |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
c = 0
a = 0
f = 0
for i in range(len(arr)):
a = a + 1
c = c + arr[i]
if a >= k:
if c / k >= threshold:
f = f + 1
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_... |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
ans = 0
total = 0
if len(arr) < k:
return 0
else:
for i in range(k):
total += arr[i]
if float(total / k) >= threshold:
ans += ... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMB... |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
presum = [0]
for num in arr:
presum.append(presum[-1] + num)
res = 0
i = 0
while i + k < len(presum):
if presum[i + k] - presum[i] >= threshold * k:
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER RETURN VAR VAR |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, A, k, target):
target *= k
s = 0
for i in range(k):
s += A[i]
res = 1 if s >= target else 0
for i in range(len(A) - k):
s += -A[i] + A[i + k]
res += 1 if s >= target else 0
return res | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER NUMBER RETURN VAR |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
i, j = 0, k - 1
total = sum(arr[i : j + 1])
target = threshold * k
res = 0
if total >= target:
res += 1
while j < len(arr) - 1:
total -= arr[i]
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR VAR |
Given an array of integers arr and two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
Example 1:
Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
Output: 3
Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively... | class Solution:
def numOfSubarrays(self, arr: List[int], k: int, threshold: int) -> int:
dp = [0] * len(arr)
dp[0] = arr[0]
for i in range(1, len(arr)):
dp[i] = dp[i - 1] + arr[i]
cn = 0
for i in range(k - 1, len(arr)):
if i == k - 1:
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER IF BIN_O... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | def CountSubarrays(arr, n):
freq = {i: (0) for i in arr}
d = len(list(freq.keys()))
count, res, i = 0, 0, 0
for j in range(n):
freq[arr[j]] += 1
if freq[arr[j]] == 1:
count += 1
if count == d:
res += n - j
while i <= j:
freq[arr... | FUNC_DEF ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF ... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, arr, n):
set1 = set(arr)
distinct_count = len(set1)
start, end = 0, 0
count = 0
res = 0
d = {}
for i in range(0, n):
if arr[i] in set1:
d[arr[i]] = 1 + d.get(arr[i], 0)
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR WHILE FUNC_CALL VAR VAR VAR... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, arr, n):
k = set(arr)
req = len(k)
mp = {}
ans = 0
i = 0
j = 0
while j < n:
if arr[j] not in mp:
mp[arr[j]] = 1
else:
mp[arr[j]] += 1
while i <... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER WHILE VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, l, n):
d = {}
for x in l:
d[x] = 0
k = len(d)
i = 0
j = 0
ans = 0
count = 0
while i < len(l):
if d[l[i]] == 0:
ans += 1
d[l[i]] += 1
while ... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR NUM... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def distinct(self, arr, start, end):
d = dict()
c = 0
for i in range(start, end):
if arr[i] not in d:
c += 1
d[arr[i]] = 1
return c
def countDistinctSubarray(self, arr, n):
res = 0
c = self.distinct(arr... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR ASSIGN V... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, arr, n):
def subs(arr, n, maxdistinct):
hm = {}
dist_cnt = 0
start, end = 0, 0
subs = 0
while end < n:
hm[arr[end]] = 1 + hm.get(arr[end], 0)
if hm[arr[end]] == 1:
... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, arr, n):
total_ele = len(set(arr))
count = {}
right = 0
window = 0
ans = 0
for i in range(n):
while right < n and window < total_ele:
if arr[right] in count:
count[arr[rig... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR VAR... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def atMostK(self, arr, n, k):
count = 0
left = 0
right = 0
map = {}
while right < n:
if arr[right] not in map:
map[arr[right]] = 0
map[arr[right]] += 1
while len(map) > k:
if arr[left] not in... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VA... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, arr, n):
t = len(set(arr))
ans = 0
left = 0
d = {}
for i in range(n):
if arr[i] not in d:
d[arr[i]] = 1
else:
d[arr[i]] += 1
while len(d) == t:
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER RETURN VA... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, arr, n):
count = {}
for i in range(len(arr)):
count[arr[i]] = 1 + count.get(arr[i], 0)
distinct = len(count)
res = {}
l = 0
ans = 0
for r in range(n):
res[arr[r]] = 1 + res.get(arr[r], 0)... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER WHILE FUNC_CAL... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, a, n):
d = {}
k = 0
for i in range(n):
if a[i] not in d.keys():
d[a[i]] = 1
k += 1
ans = 0
i = 0
d = {}
while i in range(n):
if a[i] not in d.keys():
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT WHILE VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSI... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def solve(self, arr, k, n):
d = {}
count, l, r = 0, 0, 0
while r < n:
if arr[r] not in d:
d[arr[r]] = 0
d[arr[r]] += 1
while len(d) > k:
if arr[l] not in d:
d[arr[l]] = 0
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR N... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, arr, n):
ans, cnt, start, k, di = 0, 0, 0, len(set(arr)), dict()
for i in range(n):
while start < n and cnt < k:
di[arr[start]] = di.get(arr[start], 0) + 1
if di[arr[start]] == 1:
cnt += ... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR V... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, arr, n):
uniq, d = len(set(arr)), {}
start = c = tot = 0
for i in range(n):
if arr[i] not in d:
d[arr[i]], c = 1, c + 1
else:
d[arr[i]] += 1
if c == uniq:
tot ... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR DICT ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR ... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, arr, n):
d = {}
for i in range(n):
d[arr[i]] = 1
p = len(d)
d1 = {}
h = 0
res = 0
l = 0
for i in range(n):
d1[arr[i]] = d1.get(arr[i], 0) + 1
if arr[i] in d and d[arr[... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUM... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, arr, n):
distinctEle = len(set(arr))
i = 0
j = 0
ans = 0
dic = {}
currDistinctEle = 0
cnt = 0
while j < n:
while i < n and currDistinctEle == distinctEle:
ans += n - j + 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR V... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, arr, n):
s = set()
for x in arr:
s.add(x)
i = -1
j = -1
count = 0
d = {}
while True:
f1 = False
f2 = False
while i < len(arr) - 1:
f1 = True
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF FUN... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, arr, n):
k = 0
hashmap = {}
for i in range(n):
curr = arr[i]
if curr in hashmap:
hashmap[curr] += 1
else:
k += 1
hashmap[curr] = 1
def fun(k):
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR N... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, arr, n):
tot = len(set(arr))
fp, sp, mp = 0, 0, {}
ans = 0
while sp < n:
if arr[sp] in mp:
mp[arr[sp]] += 1
else:
mp[arr[sp]] = 1
while len(mp) == tot and fp <= sp:
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER DICT ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR N... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, arr, n):
uniq = 0
dt, ds = {}, {}
for i in range(n):
if dt.get(arr[i], 0) == 0:
uniq += 1
dt[arr[i]] = 1
start = end = ans = 0
cnt = 0
for i in range(n):
if ds.get(arr... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR DICT DICT FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL ... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, arr, n):
vis = dict()
for i in range(n):
vis[arr[i]] = 1
k = len(vis)
vid = dict()
ans = 0
right = 0
window = 0
for left in range(n):
while right < n and window < k:
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBE... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, arr, n):
k = len(set(arr))
has = {}
i = -1
j = -1
ans = 0
while True:
f1 = False
f2 = False
while i < n - 1:
f1 = True
i += 1
has[arr[i... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, str, n):
x = len(set(str))
st = 0
d = {}
ans = 99999999
l = 0
c = 0
r = False
z = 0
for i in range(n):
if str[i] in d:
d[str[i]] += 1
else:
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR BIN_OP BIN_OP VAR ... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def check_distinct(self, subarray_freq, unique_elem_hm):
for key in unique_elem_hm:
if subarray_freq[key] == 0:
return False
return True
def countDistinctSubarray(self, nums, n):
unique_elem_hm = {}
for i in range(n):
uniq... | CLASS_DEF FUNC_DEF FOR VAR VAR IF VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, arr, n):
e = 0
d = {}
for i in range(n):
if arr[i] not in d:
d[arr[i]] = 1
e += 1
d = {}
i = 0
j = n - 1
while i < n:
if arr[i] in d:
d[arr... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER A... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, arr, n):
a = [0] * 100000
k = 0
for i in range(n):
if a[arr[i]] == 0:
a[arr[i]] += 1
k += 1
else:
a[arr[i]] += 1
a = [0] * 1000000
value = 0
z = 0
... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR... |
Given an array arr[] of n integers. Count the total number of sub-array having total distinct elements same as that of total distinct elements of the original array.
Example 1:
Input:
N=5
arr[] = {2, 1, 3, 2, 3}
Output: 5
Explanation:
Total distinct elements in array is 3
Total sub-arrays that satisfy the condition
... | class Solution:
def countDistinctSubarray(self, arr, n):
hash_arr = {}
k = 0
for num in arr:
if num not in hash_arr:
k += 1
hash_arr[num] = 1
else:
hash_arr[num] += 1
hash_arr = {}
match_cnt = 0
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR V... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.