description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | t = int(input())
for _ in range(t):
n, k = map(int, input().split())
a = list(map(int, input().split()))
pre = a[0]
cnt = 0
ans = 0
for cur in a[1:]:
if pre < 2 * cur:
cnt += 1
else:
cnt = 0
if cnt >= k:
ans += 1
pre = cur
p... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | import sys
def get_ints():
return map(int, sys.stdin.readline().strip().split())
def get_list():
return list(map(int, sys.stdin.readline().strip().split()))
def get_string():
return sys.stdin.readline().strip()
t = int(input())
for _ in range(t):
n, k = get_ints()
arr = get_list()
cnt = ... | IMPORT 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSI... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | for _ in range(int(input())):
n, k = input().split(" ")
n, k = int(n), int(k)
arr = input().split(" ")
k += 1
temp = 1
ans = 0
for i in range(n):
arr[i] = int(arr[i])
if i != 0 and 2 * arr[i] > arr[i - 1]:
temp += 1
else:
temp = 1
ans +... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER BIN_OP ... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | n = int(input())
for i in range(n):
l = list(map(int, input().split()))
long = l[0]
equ = l[1]
s = list(map(int, input().split()))
s.append(0)
num = 0
tip = []
ans = 0
for j in range(long):
if s[j] < 2 * s[j + 1]:
num += 1
else:
tip.append(num)... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | for _ in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
a = [(a[i + 1] * 2 > a[i]) for i in range(n - 1)]
s = sum(a[:k])
count = int(s == k)
for i in range(n - k - 1):
s += a[i + k] - a[i]
if s == k:
count += 1
print(coun... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL V... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | t = int(input())
for _ in range(t):
n, k = [int(x) for x in input().split()]
k += 1
a = [int(x) for x in input().split()]
broken = [-1] + [i for i in range(n - 1) if a[i] >= 2 * a[i + 1]] + [n - 1]
print(
sum(max(0, broken[i + 1] - broken[i] - k + 1) for i in range(len(broken) - 1))
) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER LIST ... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | for x in range(int(input())):
n, k = map(int, input().split())
l = list(map(int, input().split()))
sub = 0
ans = [0] * n
for x in range(n - 1):
if l[x] < l[x + 1] * 2:
ans[x] = 1
s = 0
for x in range(k):
s += ans[x]
if s == k:
sub += 1
for y in ran... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN ... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | for _ in range(int(input())):
n, k = list(map(int, input().split()))
lis = list(map(int, input().split()))
c = 0
v = 0
for i in range(n - 1):
if lis[i] >= 2 * lis[i + 1]:
c += max(v - k + 1, 0)
v = 0
else:
v += 1
c += max(v - k + 1, 0)
prin... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR FUNC_... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | import sys
from sys import stdin, stdout
sys.setrecursionlimit(10**6)
I = stdin.readline
O = stdout.write
def bi(n):
return bin(n).replace("0b", "")
def solve():
n, k = list(map(int, input().split()))
arr = list(map(int, input().split()))
fin = [(1) for i in range(n)]
for i in range(1, n):
... | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR VAR STRING STRING FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VA... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | testcase = int(input())
for _ in range(testcase):
n, k = list(map(int, input().split()))
lists = list(map(int, input().split()))
left = 0
count = 0
for right in range(1, len(lists)):
if lists[right] * 2 <= lists[right - 1]:
left = right
if right - left >= k:
c... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_O... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | def solve():
n, k = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
ct = 1
for i in range(1, n):
if 2 * l[i] > l[i - 1]:
ct += 1
else:
ct = 1
if ct > k:
ans += 1
print(ans)
for t in range(int(input())):
solve... | FUNC_DEF ASSIGN VAR 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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR V... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | def sol():
n, k = map(int, input().split())
l = list(map(int, input().split()))
tl = [0] * n
tl[0] = 1
ans = 0
for i in range(1, n):
if 2 * l[i] > l[i - 1]:
tl[i] = tl[i - 1] + 1
else:
tl[i] = 1
for i in tl:
if i > k:
ans += 1
p... | FUNC_DEF ASSIGN VAR 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 BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | import sys
input = sys.stdin.readline
def solve():
n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
cnt = 0
for j in range(k):
cnt += a[j] >= a[j + 1] * 2
for i in range(n - k):
ans += cnt == 0
cnt -= a[i] >= a[i + 1] * 2
if i + 1 + ... | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR 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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER VAR... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | import itertools
for _ in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.append(0)
cnt = 0
res = 0
for i in range(n):
if a[i] < 2 * a[i + 1]:
cnt += 1
else:
if cnt >= k:
res += cnt - k + 1
... | IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR ... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | t = int(input())
for i in range(t):
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * (n - 1)
for i in range(n - 1):
b[i] = 1 if a[i] < 2 * a[i + 1] else 0
ans = 0
c = sum(b[:k])
if c == k:
ans += 1
for i in range(n - k - 1):
c -= b[i]... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP NUMBER VAR BI... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | t = int(input())
for case in range(t):
n, k = map(int, input().split(" "))
arr = list(map(int, input().split(" ")))
consecutive = 0
count = 0
for j in range(n - 1):
if arr[j] < 2 * arr[j + 1]:
if consecutive < k:
consecutive += 1
if consecutive == k:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP NUMBER VAR BIN_OP VAR N... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | a = int(input())
for y in range(a):
b, c = map(int, input().split())
d = list(map(int, input().split()))
l = 0
f = 1
o = 0
for y in range(1, b - c):
if 2 * d[y] <= d[y - 1]:
l = y
if f - (c + 1) + 1 > 0:
o += f - (c + 1) + 1
f = 1
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR IF BIN_OP NUMBER VAR VAR VAR BIN_... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | for t in range(int(input())):
n, k = map(int, input().split())
cnt = 0
temp = 0
last = 0
i = 1
for a in map(int, input().split()):
if a * 2 > last:
temp += 1
if i == n:
cnt += max(0, temp - k)
else:
cnt += max(0, temp - k)
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR ... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | import itertools
for _ in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
print(
sum(
max(sum(1 for _ in g) + 1 - k, 0)
for t, g in itertools.groupby(i < j + j for i, j in zip(a, a[1:]))
if t
)
) | IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR FUNC_CALL VAR VAR BIN_O... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | for _ in range(int(input())):
n, k = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr_bool = [True]
for i in range(1, n):
if arr[i - 1] < 2 * arr[i]:
arr_bool.append(True)
else:
arr_bool.append(False)
arr_bool.append(False)
i = 0
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER EXP... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | def read_arr():
return list(map(int, input().split(" ")))
_t = 1
_t = int(input())
for _i in range(_t):
n, k = read_arr()
A = read_arr()
B = [0] * n
ans, cur = 0, 0
for i in range(1, n):
if A[i] * 2 > A[i - 1]:
B[i] = 1
for b in B:
if b == 1:
cur += ... | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_O... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | for i in range(int(input())):
a, b = map(int, input().split())
lis = list(map(int, input().split()))
ans = 0
c = 1
an = ""
for i in range(a - 1):
if lis[i] < 2 * lis[i + 1]:
c += 1
else:
if c - b > 0:
ans += c - b
c = 1
if c... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR N... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | def sort_2(n, k, l):
c = 1
i = 1
ans = 0
while i < n:
if 2 * l[i] > l[i - 1]:
c += 1
else:
c = 1
if c >= k + 1:
ans += 1
i += 1
return ans
for i in range(int(input())):
[n, k] = list(map(int, input().split()))
l = list(map... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN LIST VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CA... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | t = int(input())
for _ in range(t):
n, k = [int(i) for i in input().strip().split()]
a = [int(i) for i in input().strip().split()]
i = 0
j = 1
ans = 0
while j < n:
while j < n and a[j] / a[j - 1] > 0.5:
j += 1
if j - i >= k + 1:
ans += j - i - k
i ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBE... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | for _ in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = [(2 * a[i] > a[i - 1]) for i in range(1, n)]
colT = sum(b[i] for i in range(k))
ans = 0
if colT == k:
ans += 1
for i in range(1, n - k):
colT += b[i + k - 1] - b[i - 1]
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN ... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | def solve():
n, k = map(int, input().split())
arr = list(map(int, input().split()))
ans = 0
count = 1
k += 1
for i in range(1, n):
if arr[i] * 2 > arr[i - 1]:
count += 1
else:
if count >= k:
ans += count - k + 1
count = 1
if... | FUNC_DEF ASSIGN VAR 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 NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIG... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | for _ in range(int(input())):
n, k = map(int, input().split())
l = list(map(int, input().split()))
b = ""
for i in range(n - 1):
if l[i] < 2 * l[i + 1]:
b += "1"
else:
b += "0"
x = b.split("0")
ans = 0
for i in x:
temp = len(i)
if k > t... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR STRING VAR STRING ASSIGN VAR FUNC_CAL... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | def solve():
n, k = map(int, input().split())
a = map(int, input().split())
a = list(a)
res = 0
t = 1
i = 1
while i < n:
while i < n and a[i - 1] < a[i] * 2:
i = i + 1
t = t + 1
if t >= k + 1:
res = res + t - k
t = 1
i = i +... | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | p = lambda: map(int, input().split())
def solve():
n, k = p()
a = [*p()]
b = [(a[i] < 2 * a[i + 1]) for i in range(n - 1)]
cnt = 0
s = 0
for i in range(k):
s += b[i]
i = 0
j = k
if s == k:
cnt += 1
while j < n - 1:
s += b[j]
s -= b[i]
if ... | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR I... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | x = int(input())
def cal(n, k, arr):
ans = 0
t = 0
for i in range(1, n):
if arr[i] * 2 > arr[i - 1]:
if i == n - 1:
ans += max(0, i - t - k + 1)
else:
ans += max(0, i - t - k)
t = i
return ans
for jj in range(x):
n, k = [int(i) ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR ... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def shift(s):
for i in range(1, len(s) + 1):
if s == s[i:] + s[:i]:
return i
for _ in range(int(input())):
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
cur = 1
ans = 0
... | FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | t = int(input())
while t:
n, k = map(int, input().split())
l = list(map(int, input().split()))
le = 1
ans = 0
for i in range(n - 1):
if 2 * l[i + 1] > l[i]:
le += 1
else:
le = 1
if le >= k + 1:
ans += 1
print(ans)
t -= 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NU... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | for _ in range(int(input())):
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
s = []
for i in range(n - 1):
if a[i] < 2 * a[i + 1]:
s.append(1)
else:
s.append(0)
cnt = 0
now = sum(s[:k])
if now == k:
cnt += 1
for ... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXP... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | t = int(input())
for _ in range(t):
n, k = map(int, input().split())
arr = list(map(int, input().split()))
l = []
for i in range(1, n):
if 2 * arr[i] > arr[i - 1]:
l.append(1)
else:
l.append(0)
cs = sum(l[:k])
ans = 0
if cs == k:
ans += 1
f... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | n = int(input())
while n > 0:
x, y = map(int, input().split())
l1 = list(map(int, input().strip().split()))
l2 = l1
l2 = [(x * 2) for x in l2]
ans = 0
k = 0
for i in range(0, x - 1):
if l1[i] < l2[i + 1]:
k += 1
else:
k = 0
if k >= y:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NU... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | t = int(input())
for j in range(t):
n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
cur = 1
for i in range(n - 1):
if cur < k:
if a[i] < a[i + 1] * 2:
cur += 1
else:
cur = 1
elif a[i] < a[i + 1] * 2:... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMB... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | t = int(input())
for i in range(t):
[n, k] = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
length = 0
ans = 0
for i in range(n):
if i == n - 1:
if length >= k:
ans += length + 1 - k
break
if arr[i] < 2 * arr[i + 1]:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR I... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | tc = int(input())
for _ in range(tc):
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
l = []
cnt1 = 1
for i in range(len(a) - 1):
if a[i] < 2 * a[i + 1]:
cnt1 += 1
elif a[i] >= 2 * a[i + 1]:
l.append(cnt1)
cnt1 = 1
l.... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP NUMBER VAR ... |
Given an array $a$ of length $n$ and an integer $k$, find the number of indices $1 \leq i \leq n - k$ such that the subarray $[a_i, \dots, a_{i+k}]$ with length $k+1$ (not with length $k$) has the following property:
If you multiply the first element by $2^0$, the second element by $2^1$, ..., and the ($k+1$)-st eleme... | t = int(input())
for i in range(t):
n, k = [int(v) for v in input().split()]
w = [int(v) for v in input().split()]
z = []
for j in range(1, n):
if w[j] * 2 > w[j - 1]:
z.append(1)
else:
z.append(0)
res = 0
c = 0
for j in range(n - 1):
if z[j] =... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL ... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
pref = {(0): -1}
result = best = math.inf
best_till = [math.inf] * len(arr)
for i, curr in enumerate(itertools.accumulate(arr)):
diff = curr - target
if diff in pref:
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL ... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
record = collections.defaultdict()
record[0] = 0
l1 = l2 = float("Inf")
tmp_sum = 0
res = float("Inf")
dp = [float("Inf") for _ in range(len(arr) + 1)]
for i in range(len(arr)):
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR VAR V... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
arr_len = len(arr)
dp = [sys.maxsize] * arr_len
left = right = 0
sum_tmp = 0
length, ans_len = sys.maxsize, sys.maxsize
while right < arr_len:
sum_tmp += arr[right]
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VA... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
result = float("inf")
leftmin = self.getMinLen(arr, target, True)
rightmin = self.getMinLen(arr, target, False)
for i in range(0, len(arr) - 1):
result = min(result, leftmin[i] + rightmin[i + ... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_CALL VAR STRING VAR NUMBER VAR FUN... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
dp = [len(arr) + 1] * len(arr)
table = {(0): -1}
s = 0
min_sum = len(arr) + 1
for i in range(len(arr)):
s += arr[i]
if i > 0:
dp[i] = dp[i - 1]
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR BIN_OP LIST BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
H = {(0): -1}
total = 0
M = len(arr) + 1
for i, a in enumerate(arr):
total += a
H[total] = i
result = M
minL = M
total = 0
for i, a in enumerate(arr... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
sums = {(0): -1}
prefix = 0
dp = [math.inf for _ in range(len(arr) + 1)]
ans = math.inf
for idx, num in enumerate(arr):
prefix += num
dp[idx + 1] = min(dp[idx + 1], dp[idx]... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
run = [0, arr[0]]
h = {(0): 0, arr[0]: 1}
prefix = [len(arr)]
for i in range(1, len(arr)):
if run[i] - target in h:
prefix.append(min(prefix[-1], i - h[run[i] - target]))
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST NUMBER VAR NUMBER ASSIGN VAR DICT NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
p = [0]
m = {(0): -1}
minLen = [float("inf")]
cur = 0
ans = best = float("inf")
for i, a in enumerate(arr):
cur += a
p.append(cur)
if cur - target in m:... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR LIST FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR STRING FOR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR ... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
def prefix_sum(arr):
lookup = {}
dp = [float("inf")] * len(arr)
cumsum = 0
for i, num in enumerate(arr):
cumsum += num
if cumsum == target:
... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR AS... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | INF = int(1000000000.0)
class Solution:
def shortest_subarrays(self, a, target):
cum = [0]
for x in a:
cum.append(cum[-1] + x)
hist = {(0): 0}
ret = [INF]
for i in range(1, len(cum)):
ci = cum[i]
begin = hist.get(ci - target, -1)
... | ASSIGN VAR FUNC_CALL VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR LIST VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL V... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
n = len(arr)
def get_dp(arr):
dp = []
ptr = 0
total = 0
min_val = float("inf")
for i in range(n):
total += arr[i]
while ptr < i... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL ... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr, target):
result = inf = 2**31 - 1
i = window = 0
premin = [inf] * len(arr)
for j in range(len(arr)):
window += arr[j]
while window > target:
window -= arr[i]
i += 1
if ... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSI... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
mp = {}
sum_list = 0
mp[0] = -1
for i, val in enumerate(arr):
sum_list += val
mp[sum_list] = i
res = float("inf")
lvalue = float("inf")
sum_list = 0
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BI... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
l = len(arr)
left, right, pre = [l] * l, [l] * l, {(0): -1}
p = 0
for i in range(l):
p += arr[i]
if p - target in pre:
prev = pre[p - target]
left[i... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP LIST VAR VAR BIN_OP LIST VAR VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR V... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
n = len(arr)
left = [float("inf")] * n
memo = {(0): -1}
current = 0
for k in range(n):
if k > 0:
left[k] = left[k - 1]
current += arr[k]
if curr... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR B... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def getMinArr(self, arr, target, right=False):
pre_sum = 0
res = [float("inf") for i in range(len(arr))]
sum_dict = {(0): 0}
if right:
arr = arr[::-1]
for i, num in enumerate(arr):
pre_sum += num
if i > 0:
r... | CLASS_DEF FUNC_DEF NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR DICT NUMBER NUMBER IF VAR ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_O... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
n = len(arr)
su = 0
s = 0
min_len = float("inf")
min_lens = [float("inf") for _ in range(n)]
ans = float("inf")
for e in range(n):
su += arr[e]
while su > t... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BI... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
if not arr:
return -1
prefixes = [0] * len(arr)
suffixes = [0] * len(arr)
left = right = 0
curr = 0
min_len = float("inf")
while right < len(arr):
curr += a... | CLASS_DEF FUNC_DEF VAR VAR VAR IF VAR RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VA... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
n = len(arr)
res = n + 1
pre = {}
pre[0] = -1
dp = [float("inf")] * n
p = 0
for i, a in enumerate(arr):
p += a
dp[i] = dp[i - 1]
if p - target i... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR B... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
start, ans, sum = 0, float("inf"), 0
best = [float("inf")] * len(arr)
best_so_far = float("inf")
for i in range(len(arr)):
sum += arr[i]
while sum > target:
sum -= ... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR STRING NUMBER ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
prefix_sum2_idx = defaultdict(int)
prefix_sum2_idx[0] = -1
prefix_sum = 0
n = len(arr)
for i in range(n):
prefix_sum += arr[i]
prefix_sum2_idx[prefix_sum] = i
prefi... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP V... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
best_so_far = [float("inf") for i in range(len(arr) + 1)]
prefix_sum = 0
prefix_sum_to_idx = {(0): -1}
res = float("inf")
for i, v in enumerate(arr):
prefix_sum += v
best_s... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR FUNC... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
lim = len(arr)
pref = [arr[0]]
d = dict()
e = dict()
d[arr[0]] = [0]
e[arr[0]] = 1
for i in range(1, lim):
pref.append(pref[-1] + arr[i])
try:
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER LIST NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR VAR VAR ... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengthsOld(self, arr: List[int], target: int) -> int:
n = len(arr)
if n == 1:
return -1
i = 0
j = 0
sum_ = arr[i]
interval = []
while i < n and j < n:
if sum_ == target:
interval.append([i, j... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR LIST WHILE VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR IF VAR VAR... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
i, window, result = 0, 0, float("inf")
premin = [float("inf")] * len(arr)
for j, num in enumerate(arr):
window += num
while window > target:
window -= arr[i]
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
preSum = {(0): -1}
n = len(arr)
curSum = 0
minLen = float("inf")
lsize = float("inf")
for i in range(n):
curSum += arr[i]
preSum[curSum] = i
curSum = 0
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FU... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
left_min = self.getMinArr(arr, target, True)
right_min = self.getMinArr(arr, target, False)
result = sys.maxsize
for i in range(0, len(arr) - 1):
if max(left_min[i], right_min[i + 1]) != sys.m... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR VAR V... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
accuArr = []
y = 0
for x in arr:
y += x
accuArr.append(y)
bestTill = [float("inf")] * len(arr)
bestTillNow = float("inf")
sum2Pos = dict()
sum2Pos[0] = -1
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR ... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
n = len(arr)
dp = [float("inf")] * n
sums, res = 0, float("inf")
sum_record = {(0): -1}
for i, num in enumerate(arr):
sums += num
dp[i] = dp[i - 1]
if sums - ta... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR STRING ASSIGN VAR DICT NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR I... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
l = r = 0
s = arr[l]
res = []
while r < len(arr):
if s == target:
ln = r - l + 1
res.append((ln, l, r))
if s <= target:
r += 1
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER IF V... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
n = len(arr)
prefixSum = [0] * n
targetSum = [sys.maxsize] * n
beforeSum = [sys.maxsize] * n
afterSum = [sys.maxsize] * n
sumDict = {(0): -1}
total = 0
for i in range(n):
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST VAR VAR ASSIGN VAR BIN_OP LIST VAR VAR ASSIGN VAR BIN_OP LIST VAR VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | import sys
class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
table = {(0): -1}
cursum = 0
dp1 = [sys.maxsize for i in range(len(arr))]
for i in range(len(arr)):
if i > 0:
dp1[i] = dp1[i - 1]
cursum += arr[i]
... | IMPORT CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR V... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
mapsum = {}
mapsum[0] = -1
totsum = 0
best_till = [math.inf] * len(arr)
best = math.inf
end = -1
res = float("inf")
for i in range(len(arr)):
totsum += arr[i]
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF VAR NUMBER AS... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
n = len(arr)
prefix = [float("INF")] * (n + 1)
suffix = [float("INF")] * (n + 1)
tmp = 0
start = 0
for i in range(n):
if arr[i] == target:
prefix[i + 1] = 1
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR V... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
left = self.shortestTails(arr, target, False)
right = self.shortestTails(arr, target, True)
mn = float("inf")
for i in range(len(arr) - 1):
if left[i][0] < float("inf") and right[i + 1][0] < f... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER FUNC_CALL VAR STRING VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_O... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
minLen = float("inf")
lsize = float("inf")
preSum = {(0): -1}
curSum = 0
for i, val in enumerate(arr):
curSum += val
preSum[curSum] = i
curSum = 0
for i, va... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VA... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
for i in range(1, len(arr)):
arr[i] += arr[i - 1]
index = {(0): -1}
best_till = [float("inf")] * len(arr)
res = float("inf")
best = float("inf")
for i, val in enumerate(arr):
... | CLASS_DEF FUNC_DEF VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR ASSI... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
prefix = {(0): -1}
res, best, dp = sys.maxsize, sys.maxsize, [sys.maxsize] * len(arr)
for i, acc in enumerate(itertools.accumulate(arr)):
if acc - target in prefix:
end = prefix[acc - ... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP LIST VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
left, right = 0, 0
valid_subarray_lengths = [(0) for _ in range(len(arr))]
cum_sum = 0
for i in range(len(arr)):
cum_sum += arr[i]
right = i
while cum_sum > target:
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NONE VAR FUNC_CALL... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
n = len(arr)
dp = [float("inf") for _ in range(n + 1)]
ans = float("inf")
start = 0
curr_sum = 0
for end in range(n):
curr_sum += arr[end]
while start < end and cur... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR B... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
n_arr = len(arr)
if n_arr == 0:
return -1
def get_minlen_ending_before(array: List[int]) -> List[int]:
n_array = len(array)
minlen_array = [float("inf")] * n_array
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING WHILE VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN V... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr, target):
result = inf = 2**31 - 1
i = window = count = 0
preMin = [(-1, inf)]
for j, num in enumerate(arr):
window += num
while window > target:
window -= arr[i]
i += 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
n = len(arr)
prefix_sum = list(accumulate(arr))
suffix_sum = list(accumulate(arr[::-1]))
def helper(prefix_sum, n, target):
dict_x = {(0): -1}
l_1 = [(n + 1) for _ in range(n)]
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
prefix = []
for n in arr:
if len(prefix) == 0:
prefix.append(n)
else:
prefix.append(prefix[-1] + n)
indexMap = {}
indexMap[0] = -1
best = ou... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
ptr1, ptr2 = 0, 0
s = arr[0]
m = [-1] * len(arr)
ans = -1
global_min = -1
while ptr2 < len(arr):
if global_min > 0:
m[ptr2] = global_min
if s == tar... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BI... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
if len(arr) < 2:
return -1
n = len(arr)
curSum = 0
prefixSum = {(0): -1}
dp = [float("inf")] * n
ans = float("inf")
for i in range(n):
curSum += arr[i]
... | CLASS_DEF FUNC_DEF VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP V... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
res = [float("inf")] * len(arr)
ans = float("inf")
currMin = float("inf")
i = 0
s = 0
for j in range(len(arr)):
s += arr[j]
while s > target:
s -= a... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VA... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
LARGE_NUMBER = 1000000000
if not arr:
return -1
psum = [0] * (len(arr) + 1)
sum2i = {}
for i in range(len(arr)):
psum[i + 1] = psum[i] + arr[i]
res = LARGE_NUMBER
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER IF VAR RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VA... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
len_to_start = collections.defaultdict(list)
start, end = 0, 1
tmp_sum = arr[0]
earliest_end, latest_start = len(arr), 0
while start < len(arr):
while end < len(arr) and tmp_sum < targ... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
INF = len(arr) + 1
best_idx = [INF] * len(arr)
best = INF
csum = 0
left = 0
for right in range(len(arr)):
csum += arr[right]
while csum > target and left <= right:
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
left = list(itertools.accumulate(arr))
right = list(itertools.accumulate(arr[::-1]))
right = right[::-1]
rans = [500000] * len(arr)
lans = [500000] * len(arr)
i, j, n = 0, 0, len(arr)
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR ASSIG... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
prefix = {(0): -1}
best_till = [math.inf] * len(arr)
ans = best = math.inf
for i in range(1, len(arr)):
arr[i] += arr[i - 1]
for i, cur in enumerate(arr):
if cur - target i... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR BIN_OP LIST VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL V... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
left_sub_array = [len(arr)] * len(arr)
sub_sum, next_index = 0, 0
for index in range(len(arr)):
while sub_sum < target and next_index < len(arr):
sub_sum += arr[next_index]
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR V... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
sP = 0
fP = 0
intervalHeap = []
sumSoFar = 0
while fP < len(arr):
sumSoFar += arr[fP]
if sumSoFar >= target:
if sumSoFar == target:
heap... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMB... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
sumArr = []
sumMap = {}
sumMap[0] = -1
for i in range(len(arr)):
sumArr.append(arr[i] + (sumArr[i - 1] if i - 1 > -1 else 0))
sumMap[sumArr[i]] = i
res = math.inf
d... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CA... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
N = len(arr)
prefix = [N + 1] * N
suffix = [N + 1] * N
presum = dict()
total = 0
presum[0] = -1
for i in range(N):
total += arr[i]
presum[total] = i
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER ASSIGN VA... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr, target):
result = inf = 2**31 - 1
i = window = count = 0
preMin = deque([(-1, inf)])
for j, num in enumerate(arr):
window += num
while window > target:
window -= arr[i]
i += 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR ASSIGN VAR B... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
if not arr:
return 0
min_at_curr = [float("inf")] * len(arr)
start = end = 0
currSum = 0
minSum = float("inf")
while end < len(arr):
currSum += arr[end]
... | CLASS_DEF FUNC_DEF VAR VAR VAR IF VAR RETURN NUMBER ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BI... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
n = len(arr)
def get_min(arr):
min_left = [float("inf")] * n
window = 0
l = 0
for r in range(n):
window += arr[r]
while window > target:
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR FUNC_CAL... |
Given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays is minimum.
Return the minimum sum of the lengths of the two required su... | class Solution:
def minSumOfLengths(self, arr: List[int], target: int) -> int:
nums = [(0) for i in range(len(arr))]
nums[0] = arr[0]
for i in range(1, len(arr)):
nums[i] = nums[i - 1] + arr[i]
best = [float("inf") for i in range(len(arr))]
ans = float("inf")
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR 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 FUNC_CALL VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.