description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Alice and Bob are playing yet another card game. This time the rules are the following. There are $n$ cards lying in a row in front of them. The $i$-th card has value $a_i$.
First, Alice chooses a non-empty consecutive segment of cards $[l; r]$ ($l \le r$). After that Bob removes a single card $j$ from that segment $... | import sys
n = int(input())
a = [int(x) for x in input().split()]
if all(x <= 0 for x in a):
print(0)
import sys
sys.exit(0)
pvs = list(reversed(sorted([x for x in set(a) if x > 0])))
obest = 0
for v in pvs:
cv = 0
poss = False
for x in a:
if x == v:
poss = True
... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER IMPORT EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR AS... |
Alice and Bob are playing yet another card game. This time the rules are the following. There are $n$ cards lying in a row in front of them. The $i$-th card has value $a_i$.
First, Alice chooses a non-empty consecutive segment of cards $[l; r]$ ($l \le r$). After that Bob removes a single card $j$ from that segment $... | import sys
input = sys.stdin.readline
def main():
n = int(input())
a = list(map(int, input().split()))
ans = 0
for m in range(31):
v = 0
for x in a:
if x > m:
v = 0
else:
v = max(v, 0) + x
ans = max(ans, v - m)
... | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR B... |
Alice and Bob are playing yet another card game. This time the rules are the following. There are $n$ cards lying in a row in front of them. The $i$-th card has value $a_i$.
First, Alice chooses a non-empty consecutive segment of cards $[l; r]$ ($l \le r$). After that Bob removes a single card $j$ from that segment $... | import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [([c] * b) for i in range(a)]
def list3d(a, b, c, d):
return [[([d] * c) for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[([e] * d) for j in range(c)] for j in range(b)] for i in ran... | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER RETURN FUNC_CALL ... |
Alice and Bob are playing yet another card game. This time the rules are the following. There are $n$ cards lying in a row in front of them. The $i$-th card has value $a_i$.
First, Alice chooses a non-empty consecutive segment of cards $[l; r]$ ($l \le r$). After that Bob removes a single card $j$ from that segment $... | from sys import stdin
input = stdin.buffer.readline
n = int(input())
(*a,) = map(int, input().split())
ans = 0
for x in range(0, 31):
if not x in a:
continue
mx = a[0] if a[0] <= x else 0
sm, mn = 0, 0
for i in range(n):
if a[i] > x:
continue
sm += a[i]
mx = ... | ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL V... |
Alice and Bob are playing yet another card game. This time the rules are the following. There are $n$ cards lying in a row in front of them. The $i$-th card has value $a_i$.
First, Alice chooses a non-empty consecutive segment of cards $[l; r]$ ($l \le r$). After that Bob removes a single card $j$ from that segment $... | n = int(input())
A = list(map(int, input().split()))
for a in A:
if a > 0:
break
else:
print(0)
exit()
if n == 1:
print(0)
exit()
ans = -1
INF = 10**18
for M in range(1, 31):
dp = [0] * n
if A[0] > M:
dp[0] = -INF
else:
dp[0] = A[0]
for i in range(1, n):
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBE... |
Alice and Bob are playing yet another card game. This time the rules are the following. There are $n$ cards lying in a row in front of them. The $i$-th card has value $a_i$.
First, Alice chooses a non-empty consecutive segment of cards $[l; r]$ ($l \le r$). After that Bob removes a single card $j$ from that segment $... | import sys
input = sys.stdin.readline
def prog():
n = int(input())
cards = list(map(int, input().split()))
maxes = [0]
for m in range(1, 31):
ans = 0
value = 0
for card in cards:
if card <= m:
value = max(card, value + card)
else:
... | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASS... |
Alice and Bob are playing yet another card game. This time the rules are the following. There are $n$ cards lying in a row in front of them. The $i$-th card has value $a_i$.
First, Alice chooses a non-empty consecutive segment of cards $[l; r]$ ($l \le r$). After that Bob removes a single card $j$ from that segment $... | n = int(input())
a = list(map(int, input().split())) + [100]
ans = 0
for i in range(-30, 31):
b = []
for x in a:
if x <= i:
b.append(x)
elif b:
m = 0
t = 0
for y in b:
t += y
ans = max(ans, t - m - i)
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR FUNC_... |
Alice and Bob are playing yet another card game. This time the rules are the following. There are $n$ cards lying in a row in front of them. The $i$-th card has value $a_i$.
First, Alice chooses a non-empty consecutive segment of cards $[l; r]$ ($l \le r$). After that Bob removes a single card $j$ from that segment $... | N = int(input())
As = list(map(int, input().split()))
dp = [-100] * 70
dp[0] = 0
ans = 0
for i, A in enumerate(As):
new_dp = [-100] * 70
new_dp[A] = A
for ma in range(-30, A + 1):
new_dp[A] = max(new_dp[A], dp[ma] + A)
for ma in range(A + 1, 31):
new_dp[ma] = dp[ma] + A
dp = new_dp
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER A... |
Alice and Bob are playing yet another card game. This time the rules are the following. There are $n$ cards lying in a row in front of them. The $i$-th card has value $a_i$.
First, Alice chooses a non-empty consecutive segment of cards $[l; r]$ ($l \le r$). After that Bob removes a single card $j$ from that segment $... | import sys
ninf = -100000000
[n] = [int(i) for i in sys.stdin.readline().split()]
cards = [int(i) for i in sys.stdin.readline().split()]
dp = [[(0) for i in range(n)] for j in range(61)]
for i in range(61):
if cards[0] <= i - 30:
dp[i][0] = cards[0]
else:
dp[i][0] = ninf
for j in range(1, n):
... | IMPORT ASSIGN VAR NUMBER ASSIGN LIST 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 VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NU... |
Alice and Bob are playing yet another card game. This time the rules are the following. There are $n$ cards lying in a row in front of them. The $i$-th card has value $a_i$.
First, Alice chooses a non-empty consecutive segment of cards $[l; r]$ ($l \le r$). After that Bob removes a single card $j$ from that segment $... | n = int(input())
a = list(map(int, input().split()))
max_sum = 0
for j in range(1, 31):
if j not in a:
continue
dp = [(0) for i in range(n)]
dp[0] = a[0]
valid_sums = []
prev = False
for i in range(n):
if a[i] <= j:
if prev:
dp[i] = max(0, a[i], a[i] +... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VA... |
Alice and Bob are playing yet another card game. This time the rules are the following. There are $n$ cards lying in a row in front of them. The $i$-th card has value $a_i$.
First, Alice chooses a non-empty consecutive segment of cards $[l; r]$ ($l \le r$). After that Bob removes a single card $j$ from that segment $... | def solve(n, ar):
ans = 0
for i in range(1, 31):
sum = 0
for j in range(n):
if sum < 0:
sum = 0
sum += ar[j]
if ar[j] > i:
sum = 0
if sum - i > ans:
ans = sum - i
print(ans)
n = int(input())
ar ... | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR F... |
Alice and Bob are playing yet another card game. This time the rules are the following. There are $n$ cards lying in a row in front of them. The $i$-th card has value $a_i$.
First, Alice chooses a non-empty consecutive segment of cards $[l; r]$ ($l \le r$). After that Bob removes a single card $j$ from that segment $... | x = int(input())
a = list(map(int, input().split()))
res = 0
for i in range(32):
s, max1, s1 = 0, 0, 0
for j in a:
if j <= i:
s += j
max1 = max(max1, s - s1)
s1 = min(s1, s)
else:
s1 = 0
s = 0
res = max(res, max1 - i)
print(res) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER A... |
Alice and Bob are playing yet another card game. This time the rules are the following. There are $n$ cards lying in a row in front of them. The $i$-th card has value $a_i$.
First, Alice chooses a non-empty consecutive segment of cards $[l; r]$ ($l \le r$). After that Bob removes a single card $j$ from that segment $... | def calc(x, mx):
if x > mx:
return float("-inf")
else:
return x
def calcmax(arr):
max_so_far = float("-inf")
currmax = 0
for i in arr:
currmax += i
if currmax > max_so_far:
max_so_far = currmax
if currmax < 0:
currmax = 0
return m... | FUNC_DEF IF VAR VAR RETURN FUNC_CALL VAR STRING RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_C... |
Alice and Bob are playing yet another card game. This time the rules are the following. There are $n$ cards lying in a row in front of them. The $i$-th card has value $a_i$.
First, Alice chooses a non-empty consecutive segment of cards $[l; r]$ ($l \le r$). After that Bob removes a single card $j$ from that segment $... | def do(arr):
res = 0
for i in range(30, -31, -1):
temp = 0
for x in arr:
if x > i:
temp = 0
else:
res = max(res, temp + x - i)
temp = max(0, temp + x)
return res
input()
lst = list(map(int, input().split()))
print(do(l... | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR RETURN VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_C... |
Alice and Bob are playing yet another card game. This time the rules are the following. There are $n$ cards lying in a row in front of them. The $i$-th card has value $a_i$.
First, Alice chooses a non-empty consecutive segment of cards $[l; r]$ ($l \le r$). After that Bob removes a single card $j$ from that segment $... | n = int(input())
s = list(map(int, input().split()))
ans = 0
inf = -99999999999999999
for mx in range(31):
c = b = 0
for i in s:
if i > mx:
i = inf
c += i
b = min(b, c)
ans = max(ans, c - b - mx)
print(ans) | ASSIGN VAR FUNC_CALL VAR 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 ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR V... |
Alice and Bob are playing yet another card game. This time the rules are the following. There are $n$ cards lying in a row in front of them. The $i$-th card has value $a_i$.
First, Alice chooses a non-empty consecutive segment of cards $[l; r]$ ($l \le r$). After that Bob removes a single card $j$ from that segment $... | n = int(input())
l = list(map(int, input().split()))
curr = 0
best = 0
prevs = [0] * 31
for v in l:
curr += v
if v >= 0:
for i in range(0, v):
prevs[i] = curr
for i in range(v, 31):
best = max(curr - prevs[i] - i, best)
else:
for i in range(31):
pr... | ASSIGN VAR FUNC_CALL VAR 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 BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL V... |
Alice and Bob are playing yet another card game. This time the rules are the following. There are $n$ cards lying in a row in front of them. The $i$-th card has value $a_i$.
First, Alice chooses a non-empty consecutive segment of cards $[l; r]$ ($l \le r$). After that Bob removes a single card $j$ from that segment $... | inf = int(1000000.0)
n = int(input())
lis = list(map(int, input().split()))
final = 0
for i in range(30, 0, -1):
s = 0
ans = 0
for j in range(n):
a = lis[j]
if lis[j] > i:
a = -inf
s += a
s = max(0, s)
ans = max(ans, s)
final = max(ans - i, final)
prin... | ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR AS... |
Alice and Bob are playing yet another card game. This time the rules are the following. There are $n$ cards lying in a row in front of them. The $i$-th card has value $a_i$.
First, Alice chooses a non-empty consecutive segment of cards $[l; r]$ ($l \le r$). After that Bob removes a single card $j$ from that segment $... | import sys
input = sys.stdin.readline
def build(a, index, beg, end, tree):
if beg == end:
tree[index][0] = a[beg]
tree[index][1] = a[beg]
else:
mid = (beg + end) // 2
build(a, 2 * index + 1, beg, mid, tree)
build(a, 2 * index + 2, mid + 1, end, tree)
tree[index... | IMPORT ASSIGN VAR VAR FUNC_DEF IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER BIN_OP V... |
Alice and Bob are playing yet another card game. This time the rules are the following. There are $n$ cards lying in a row in front of them. The $i$-th card has value $a_i$.
First, Alice chooses a non-empty consecutive segment of cards $[l; r]$ ($l \le r$). After that Bob removes a single card $j$ from that segment $... | import sys
def I():
return sys.stdin.readline().rstrip()
def f(l):
m = max(l)
if m <= 0:
return 0
s = 0
ms = 0
for x in l:
s += x
ms = max(ms, s)
s = max(s, 0)
ans = max(ms - m, 0)
le = 0
ri = -1
while le < len(l):
le = ri + 1
r... | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER... |
Alice and Bob are playing yet another card game. This time the rules are the following. There are $n$ cards lying in a row in front of them. The $i$-th card has value $a_i$.
First, Alice chooses a non-empty consecutive segment of cards $[l; r]$ ($l \le r$). After that Bob removes a single card $j$ from that segment $... | a = []
n = 0
def tryit(mx):
gs = 0
cs = 0
cmx = -float("inf")
for i in a:
if i > mx:
cs = 0
cmx = -float("inf")
continue
cs = max(i, cs + i)
if cs == i:
cmx = i
cmx = max(cmx, i)
gs = max(gs, cs - cmx)
return g... | ASSIGN VAR LIST ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_... |
Alice and Bob are playing yet another card game. This time the rules are the following. There are $n$ cards lying in a row in front of them. The $i$-th card has value $a_i$.
First, Alice chooses a non-empty consecutive segment of cards $[l; r]$ ($l \le r$). After that Bob removes a single card $j$ from that segment $... | def solve(n, d):
maxScore = 0
maxer = float("-inf")
res = 0
for i in range(31):
sub = float("-inf")
curr = float("-inf")
for j in range(len(d)):
now = d[j]
if d[j] > i:
now = float("-inf")
sub = max(sub + now, now)
c... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ... |
Alice and Bob are playing yet another card game. This time the rules are the following. There are $n$ cards lying in a row in front of them. The $i$-th card has value $a_i$.
First, Alice chooses a non-empty consecutive segment of cards $[l; r]$ ($l \le r$). After that Bob removes a single card $j$ from that segment $... | INF = 100000000000000000000000000000000000000000000000000
n, a, resp = int(input()), list(map(int, input().split())), 0
for ale in range(31):
corrente, melhor = 0, 0
for i in range(n):
val = -INF if a[i] > ale else a[i]
corrente += val
melhor = min(melhor, corrente)
resp = max(re... | ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN... |
Frog Gorf is traveling through Swamp kingdom. Unfortunately, after a poor jump, he fell into a well of $n$ meters depth. Now Gorf is on the bottom of the well and has a long way up.
The surface of the well's walls vary in quality: somewhere they are slippery, but somewhere have convenient ledges. In other words, if Go... | import sys
input = sys.stdin.readline
def solve():
n = int(input())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))
ans = []
lo, hi = n, n - A[n]
if hi <= 0:
print(1)
print(0)
return
while lo > 0:
nextStep = hi
id... | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_... |
Frog Gorf is traveling through Swamp kingdom. Unfortunately, after a poor jump, he fell into a well of $n$ meters depth. Now Gorf is on the bottom of the well and has a long way up.
The surface of the well's walls vary in quality: somewhere they are slippery, but somewhere have convenient ledges. In other words, if Go... | def task5(n, a, b):
F = [None] * (n + 1)
paths = [[] for i in range(n + 1)]
F[n] = 0
visited = set()
current = [n]
high = n
while True:
new_vertexes = []
for i in current:
for j in range(i - a[i], high + 1):
k = j + b[j]
if k not in... | FUNC_DEF ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR ASSIGN VAR VAR WHILE NUMBER ASSIGN VAR LIST FOR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR I... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
start = 0
sliding_window_counter = collections.Counter()
result = 0
for end in range(len(nums)):
sliding_window_counter[nums[end]] += 1
while sliding_window_counter[0] > 1:
sli... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER WHILE VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR VAR |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
se = set(nums)
if 0 not in se:
return len(nums) - 1
elif 1 not in se:
return 0
count = 0
flag = 0
ls = []
for i in nums:
if i == 0:
if flag ... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF NUMBER VAR RETURN BIN_OP FUNC_CALL VAR VAR NUMBER IF NUMBER VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUM... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
i, r = 0, 1
for j in range(len(nums)):
if nums[j] == 0:
r -= 1
if r < 0:
print("yes")
if nums[i] == 0:
r += 1
i += 1
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN BIN_OP VAR VAR VAR |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
prevStart = -1
candidates = []
if 0 not in nums:
return len(nums) - 1
for i in range(len(nums)):
if nums[i] == 1:
if prevStart == -1:
prevStart = i
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST IF NUMBER VAR RETURN BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR LIST VAR... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
start, end, maxlen, k = 0, 0, 0, 1
while end < len(nums):
if nums[end] == 0:
k = k - 1
if k < 0:
if nums[start] == 0:
k += 1
start = start +... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP V... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
deleted = False
max_, cur_cnt, last_cnt = 0, 0, 0
idx, size = 0, len(nums)
while idx < size and nums[idx] == 0:
idx += 1
for i in range(idx, size):
if nums[i] == 1:
cur... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR ASSIGN VAR NUMBER VAR VAR ASSIGN VAR VAR IF VAR FUNC_CAL... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
n = len(nums)
if sum(nums) == n:
return n - 1
dp = [[(0) for x in range(len(nums))] for y in range(2)]
dp[0][0] = 1 if nums[0] == 1 else 0
for i in range(1, len(nums)):
if nums[i] == 0... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR RETURN BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NU... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, a: List[int]) -> int:
ones = 0
old_ones = 0
maxlen = 0
n = len(a)
for i in range(n):
if a[i] == 1:
ones += 1
maxlen = max(maxlen, ones + old_ones)
else:
old_ones... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER RETURN VAR VAR VAR BIN_OP VAR NUMBER VAR |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
if 0 in nums and 1 in nums:
longest = 0
i = nums.index(0)
while True:
if 0 in nums[:i][::-1]:
left_side = nums[:i][::-1].index(0)
else:
... | CLASS_DEF FUNC_DEF VAR VAR IF NUMBER VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER WHILE NUMBER IF NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
if len(nums) < 1:
return 0
res = 0
logs = []
for x in nums:
if x == 0:
logs.append(res)
res = 0
else:
res += 1
logs.append(r... | CLASS_DEF FUNC_DEF VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
s = []
i = 0
while i < len(nums):
if nums[i] == 0:
s.append(0)
i += 1
else:
j = i
cnt = 0
while j < len(nums) and nums[j... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER FUN... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
right = [(0) for _ in range(len(nums))]
left = [(0) for _ in range(len(nums))]
for i in range(1, len(nums)):
if nums[i - 1] == 1:
left[i] = 1 + left[i - 1]
res = float("-inf")
for ... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR B... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
mc = 0
onep = False
for i in range(len(nums)):
if nums[i] == 0:
c = 0
j = i - 1
while j >= 0 and nums[j] != 0:
j -= 1
c += 1... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF V... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
groups = [[k, len(list(g))] for k, g in itertools.groupby(nums)]
if len(groups) == 1:
return groups[0][1] - 1 if groups[0][0] else 0
ans = 0
for i in range(len(groups)):
k, klen = groups[i]
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
seq = [0]
prev = 0
res = 0
for n in nums:
if n:
seq[-1] += 1
res = max(prev + seq[-1], res)
else:
prev = seq[-1]
seq.append(0)
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER RETURN VAR VAR |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
zero = -1
k = 1
maxi = 0
count = 0
i = 0
while i != len(nums):
if nums[i] == 0:
if k == 0:
i = zero + 1
zero = i
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
l = 0
r = 0
earliest_one = float("inf")
earliest_zero = float("inf")
zeros = 1
max_len = 0
while r < len(nums):
zeros -= nums[r] == 0
if zeros < 0:
zero... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER VAR |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
z = [0]
l = []
a = 0
c = 0
for i in range(len(nums)):
if a == 1 and nums[i] == 0:
z.append(c)
c = i - (l[-1] + 1)
a = 1
l.append(i)
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VA... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
new_array = list()
current_segment = 0
for num in nums:
if num == 0:
if current_segment > 0:
new_array.append(current_segment)
current_segment = 0
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
i, j = 0, 0
ans, cur = 0, 0
while j < len(nums):
cur += nums[j]
while i < j and cur < j - i:
cur -= nums[i]
i += 1
ans = max(ans, cur)
j += 1
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR WHILE VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
c = 0
ind = 0
for i in range(len(nums)):
if nums[i] == 0:
j = i + 1
k = 0
while j < len(nums) and nums[j] == 1:
k += 1
j += ... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER IF V... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
max_length = 0
count = 0
for num in nums:
if num == 1:
count += 1
max_length = max(max_length, count)
else:
count = 0
if max_length == len(nums)... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMB... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, array: List[int]) -> int:
i = 0
lenght = 0
stack = deque()
zero = False
while i < len(array):
if array[i] == 1:
stack.append(array[i])
i += 1
elif zero == False:
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
left = 0
right = 0
zeroes = 1
res = 0
while right < len(nums):
if nums[right] == 0:
zeroes -= 1
while zeroes < 0:
if nums[left] == 0:
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR VAR |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
if 1 not in nums:
return 0
if 0 not in nums:
return len(nums) - 1
new = []
i = 0
n = len(nums)
while i < n:
if nums[i] == 1:
cnt = 0
... | CLASS_DEF FUNC_DEF VAR VAR IF NUMBER VAR RETURN NUMBER IF NUMBER VAR RETURN BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
left = []
total = 0
for n in nums:
if n == 0:
total = 0
else:
total += n
left.append(total)
right = []
total = 0
for i in range(len(... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR ... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
n = len(nums)
leftones = [0] * n
for i in range(n):
if nums[i] == 0:
leftones[i] = 0
else:
leftones[i] = 1 if i == 0 else leftones[i - 1] + 1
rightones = [0] * ... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR ... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
prev, _next, n = (
[(0) for _ in range(len(nums))],
[(0) for _ in range(len(nums))],
len(nums),
)
count = 0
for i in range(n):
num = nums[i]
if i == 0:
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER IF VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR N... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
prev = 0
prev_zero = 0
result = float("-inf")
boolean = False
count = 0
for i in range(len(nums)):
if nums[i] == 0:
boolean = True
count += 1
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums):
n = len(nums)
last_zero = None
last_one = None
cnt = 0
res = 0
for i in range(n):
if nums[i] == 1:
if last_one is None:
last_one = i
cnt += 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR NONE ASSIGN VAR VAR VAR NUMBER IF VAR NONE ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR ... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
noofones = 0
m = 0
lastoneslen = 0
for i in nums:
if i == 1:
noofones += 1
else:
m = max(m, noofones + lastoneslen)
lastoneslen = noofones
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR VAR |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
n = len(nums)
if n == 0:
return 0
joined = [(0) for i in range(n)]
left = 0
right = 0
for i in range(n):
joined[i] += left
joined[n - 1 - i] += right
if... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER VAR NU... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
if not 0 in nums:
return len(nums) - 1
ans = 0
tot = 0
prev = 0
for n in nums:
if n == 1:
tot += 1
else:
ans = max(tot + prev, ans)
... | CLASS_DEF FUNC_DEF VAR VAR IF NUMBER VAR RETURN BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR VAR |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
start = end = zeros = ones = maxx = 0
while end < len(nums):
if nums[end] == 1:
ones += 1
elif nums[end] == 0:
zeros += 1
while zeros > 1:
if nums[s... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR VAR |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
arr = []
count = 0
for i in range(len(nums)):
if nums[i] == 1:
count += 1
elif nums[i] == 0:
arr.append(count)
count = 0
arr.append(count)
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER F... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
prev, curr, best = 0, 0, 0
n = len(nums)
for i, x in enumerate(nums):
if x == 0:
best = max(best, prev + curr)
if i == n - 1:
pass
elif nums[i +... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
res = []
count = 0
for i, val in enumerate(nums):
if val == 0:
if count > 0:
res.append(count)
count = 0
res.append(0)
elif val ... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUN... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
longest = 0
left = 0
x = 1
for right in range(len(nums)):
if not nums[right]:
x -= 1
while x < 0:
if not nums[left]:
x += 1
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN BIN_OP VAR NUMBER VAR |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
if len(nums) < 2:
return 0
len1_prev = 0
len1 = 0
i = 0
res = 0
zc = 0
while i < len(nums):
if nums[i] == 1:
len1 += 1
else:
... | CLASS_DEF FUNC_DEF VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NU... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
w_start = 0
d = {}
max_len = 0
case = 0
for i in range(0, len(nums)):
c = str(nums[i])
if c not in d:
d[c] = 0
d[c] += 1
if str(0) in d:
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR NUMBER VAR WHILE VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, A):
if not A:
return 0
n = len(A)
right = 0
cnt = 0
res = 0
for left in range(n):
while right <= n - 1 and (cnt == 0 or A[right] == 1):
cnt += A[right] == 0
right += 1
... | CLASS_DEF FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER RETURN BIN_OP VAR NUMBER |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, xs: List[int]) -> int:
n = len(xs)
if n < 2:
return 0
dp = collections.deque()
best = 0
for i, x in enumerate(xs):
if x:
dp.append(i)
while dp and i - dp[0] - len(dp) + 1 > 1:
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR VAR WHILE VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP ... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
i = 0
j = 0
sum = 0
ans = 0
for j, val in enumerate(nums):
sum += val
while i < j and sum < j - i:
sum -= nums[i]
i += 1
ans = max(ans, j - ... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR WHILE VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR VAR |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
zc, oc = 0, 0
for i, v in enumerate(nums):
if v:
oc += 1
else:
zc += 1
if oc == len(nums):
return oc - 1
elif zc == len(nums):
return 0
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMB... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | def get_longest(nums):
arr = [(1 - x) for x in nums]
l, r = 0, 0
count = 0
max_length = 0
while l < len(arr):
if r == len(arr):
step = "l"
elif l == r:
step = "r"
elif count + arr[r] > 1:
step = "l"
else:
step = "r"
... | FUNC_DEF ASSIGN VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR STRING IF VAR VAR ASSIGN VAR STRING IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING IF VAR STRING VAR VAR VAR VAR NUMBER VAR VAR... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
n = len(nums)
prev = 0
cnt = 0
pmax = 0
for i in range(0, n):
if nums[i] == 1:
cnt += 1
else:
prev = cnt
cnt = 0
maxm = prev... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR RETURN BIN_OP VAR NUMBER RETURN VAR VAR VAR VAR VAR |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
if 0 not in nums:
return len(nums) - 1
arr = [0]
count, flag = 0, 0
for idx, num in enumerate(nums):
if num == 0:
if flag == 1:
arr.append(count)
... | CLASS_DEF FUNC_DEF VAR VAR IF NUMBER VAR RETURN BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
i = 0
ints = []
while i < len(nums):
start = i
end = i
while i < len(nums) and nums[i] == 1:
i += 1
end += 1
if start != end:
in... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER IF VA... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
n = len(nums)
l, r = [0] * n, [0] * n
for i in range(1, n):
l[i] = l[i - 1] + 1 if nums[i - 1] == 1 else 0
for i in range(n - 2, -1, -1):
r[i] = r[i + 1] + 1 if nums[i + 1] == 1 else 0
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
res = zeros = 0
zero_i = None
i = 0
for j, v in enumerate(nums):
if v == 0:
zeros += 1
if zeros == 2:
i = zero_i + 1
zeros = 1
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NONE ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR VAR |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
if all(nums):
return len(nums) - 1
m = pre = l = pl = 0
for i, n in enumerate(nums):
if n == pre == 1:
l += 1
elif n == pre == 0:
pl = 0
elif n ... | CLASS_DEF FUNC_DEF VAR VAR IF FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VA... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
max_len = 0
zero_seen = False
for i in range(len(nums)):
length = 0
if nums[i] == 0:
zero_seen = True
l, r = i - 1, i + 1
while l >= 0 and nums[l] == 1:... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER VAR ... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
prev, res, curr = 0, 0, 0
for i in range(len(nums)):
if nums[i] == 1:
curr += 1
else:
if i < len(nums) - 1 and nums[i + 1] != 0:
prev = curr
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR FUNC_CALL VAR ... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
if not nums:
return 0
if all(nums):
return len(nums) - 1
n = len(nums)
dp = [([0] * 2) for _ in range(n)]
dp[0][0] = 1 if nums[0] == 1 else 0
dp[0][1] = 0
res = 0
... | CLASS_DEF FUNC_DEF VAR VAR IF VAR RETURN NUMBER IF FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
low, high = 0, 0
cn = 0
ans = 0
while low < len(nums) and high < len(nums):
if nums[high] == 0:
if cn < 1:
cn += 1
else:
while nums[... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR NUMBER VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR BIN_O... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
var = 0
count = 0
max1 = 0
pos = 0
flag = 0
for i in nums:
if i == 1:
flag = 1
if var == 1:
pos = pos + 1
count = count ... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUM... |
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1'sΒ in the resulting array.
Return 0 if there is no such subarray.
Β
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 n... | class Solution:
def longestSubarray(self, nums: List[int]) -> int:
if sum(nums) >= len(nums) - 1:
return len(nums) - 1
l = 0
while nums[l] == 0:
l += 1
if l == len(nums):
return 0
r = l + 1
sum_total = nums[l]
res =... | CLASS_DEF FUNC_DEF VAR VAR IF FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VA... |
Given two strings S and P. Find the smallest window in the string S consisting of all the characters(including duplicates) of the string P. Return "-1" in case there is no such window present. In case there are multiple such windows of same length, return the one with the least starting index.
Note : All characters ar... | class Solution:
def smallestWindow(self, S, P):
char_count_p = {}
for c in P:
char_count_p[c] = char_count_p.get(c, 0) + 1
char_count_s = {}
left, right, matched, required = 0, 0, 0, len(char_count_p)
min_window_len, min_window_start = float("inf"), None
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR STRING NONE WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NU... |
Given two strings S and P. Find the smallest window in the string S consisting of all the characters(including duplicates) of the string P. Return "-1" in case there is no such window present. In case there are multiple such windows of same length, return the one with the least starting index.
Note : All characters ar... | class Solution:
def smallestWindow(self, s, p):
count = 0
mp = [0] * 256
for i in range(len(p)):
if mp[ord(p[i])] == 0:
count += 1
mp[ord(p[i])] += 1
res = float("inf")
start = 0
i, j = 0, 0
while j < len(s):
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR V... |
Given two strings S and P. Find the smallest window in the string S consisting of all the characters(including duplicates) of the string P. Return "-1" in case there is no such window present. In case there are multiple such windows of same length, return the one with the least starting index.
Note : All characters ar... | class Solution:
def smallestWindow(self, s, p):
n = len(s)
D = {}
var = "-1"
for k in p:
if k in D:
D[k] += 1
else:
D[k] = 1
i, j = 0, 0
count = len(D)
mini = 9999
while j < n:
if s[j... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR STRING FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER WHILE VAR NUMBER IF B... |
Given two strings S and P. Find the smallest window in the string S consisting of all the characters(including duplicates) of the string P. Return "-1" in case there is no such window present. In case there are multiple such windows of same length, return the one with the least starting index.
Note : All characters ar... | class Solution:
def smallestWindow(self, s, p):
if p == "":
return -1
countT, window = {}, {}
for c in p:
countT[c] = 1 + countT.get(c, 0)
l = 0
have, need = 0, len(countT)
res, resLen = [-1, -1], float("inf")
for r in range(len(s)):
... | CLASS_DEF FUNC_DEF IF VAR STRING RETURN NUMBER ASSIGN VAR VAR DICT DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR LIST NUMBER NUMBER FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR... |
Given two strings S and P. Find the smallest window in the string S consisting of all the characters(including duplicates) of the string P. Return "-1" in case there is no such window present. In case there are multiple such windows of same length, return the one with the least starting index.
Note : All characters ar... | class Solution:
def smallestWindow(self, s, p):
no_of_chars = 256
len1 = len(s)
len2 = len(p)
if len1 < len2:
return -1
hash_p = [0] * no_of_chars
hash_str = [0] * no_of_chars
for i in range(0, len2):
hash_p[ord(p[i])] += 1
sta... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR STRING ASSIGN VAR N... |
Given two strings S and P. Find the smallest window in the string S consisting of all the characters(including duplicates) of the string P. Return "-1" in case there is no such window present. In case there are multiple such windows of same length, return the one with the least starting index.
Note : All characters ar... | class Solution:
def smallestWindow(self, s, p):
start = 0
end = 0
freq = [0] * 26
n = len(s)
size = 0
st = set(p)
m = len(st)
freq_target = [0] * 26
for i in p:
freq_target[ord(i) - ord("a")] += 1
min_size = 9999999
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER... |
Given two strings S and P. Find the smallest window in the string S consisting of all the characters(including duplicates) of the string P. Return "-1" in case there is no such window present. In case there are multiple such windows of same length, return the one with the least starting index.
Note : All characters ar... | class Solution:
def smallestWindow(self, s, p):
if len(s) < len(p):
return -1
ans = s + "1"
i = 0
j = -1
m = {}
for x in p:
if x in m:
m[x] += 1
else:
m[x] = 1
count = 0
while j < len... | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ... |
Given two strings S and P. Find the smallest window in the string S consisting of all the characters(including duplicates) of the string P. Return "-1" in case there is no such window present. In case there are multiple such windows of same length, return the one with the least starting index.
Note : All characters ar... | class Solution:
def smallestWindow(self, s, p):
Ans = len(s)
Dict = {}
for i in p:
if i in Dict:
Dict[i] = Dict[i] + 1
else:
Dict[i] = 1
count = len(Dict)
i = 0
start = 0
j = 0
while j < len(s):
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASS... |
Given two strings S and P. Find the smallest window in the string S consisting of all the characters(including duplicates) of the string P. Return "-1" in case there is no such window present. In case there are multiple such windows of same length, return the one with the least starting index.
Note : All characters ar... | class Solution:
def smallestWindow(self, s, t):
n = len(s)
r = {}
res = s
found = False
for c in list(t):
if c in r:
r[c] += 1
else:
r[c] = 1
curr = ""
for j in range(n):
c = s[j]
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VA... |
Given two strings S and P. Find the smallest window in the string S consisting of all the characters(including duplicates) of the string P. Return "-1" in case there is no such window present. In case there are multiple such windows of same length, return the one with the least starting index.
Note : All characters ar... | class Solution:
def smallestWindow(self, s, p):
d = {}
for i in p:
if i not in d:
d[i] = 1
else:
d[i] += 1
count = len(d)
res = len(s)
i, j, st = 0, 0, 0
while i < len(s):
if s[i] in d:
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF VAR... |
Given two strings S and P. Find the smallest window in the string S consisting of all the characters(including duplicates) of the string P. Return "-1" in case there is no such window present. In case there are multiple such windows of same length, return the one with the least starting index.
Note : All characters ar... | class Solution:
def smallestWindow(self, s, p):
frequencyP = {}
for ch in p:
frequencyP[ch] = frequencyP.get(ch, 0) + 1
start, end = 0, 0
count = len(p)
minLen = float("inf")
minStart = 0
while end < len(s):
if s[end] in frequencyP:
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER WHILE VAR NUMBER... |
Given two strings S and P. Find the smallest window in the string S consisting of all the characters(including duplicates) of the string P. Return "-1" in case there is no such window present. In case there are multiple such windows of same length, return the one with the least starting index.
Note : All characters ar... | class Solution:
def smallestWindow(self, s, p):
if len(s) < len(p):
return -1
d1 = {}
d2 = {}
for i in p:
if i in d1:
d1[i] += 1
else:
d1[i] = 1
count = 0
start = 0
l = 9999999999999
... | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR... |
Given two strings S and P. Find the smallest window in the string S consisting of all the characters(including duplicates) of the string P. Return "-1" in case there is no such window present. In case there are multiple such windows of same length, return the one with the least starting index.
Note : All characters ar... | class Solution:
def smallestWindow(self, s, p):
need = {}
have = {}
for char in p:
need[char] = need.get(char, 0) + 1
haveNum = 0
needNum = len(need)
n = len(s)
l = r = 0
minLen = float("inf")
res = [-1, -1]
while r < n:
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR LIST NUMBER NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR... |
Given two strings S and P. Find the smallest window in the string S consisting of all the characters(including duplicates) of the string P. Return "-1" in case there is no such window present. In case there are multiple such windows of same length, return the one with the least starting index.
Note : All characters ar... | class Solution:
def smallestWindow(self, s, t):
if t == "":
return ""
countT, window = {}, {}
have = 0
for c in t:
countT[c] = 1 + countT.get(c, 0)
need = len(countT)
res = [-1, -1]
resLen = float("infinity")
l = 0
for ... | CLASS_DEF FUNC_DEF IF VAR STRING RETURN STRING ASSIGN VAR VAR DICT DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ... |
Given two strings S and P. Find the smallest window in the string S consisting of all the characters(including duplicates) of the string P. Return "-1" in case there is no such window present. In case there are multiple such windows of same length, return the one with the least starting index.
Note : All characters ar... | class Solution:
def smallestWindow(self, s, p):
n = len(s)
m = len(p)
if m > n:
return "-1"
sFreq = [0] * 26
pFreq = [0] * 26
for i in range(m):
pFreq[ord(p[i]) - ord("a")] += 1
start = 0
end = 0
count = 0
minLe... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASS... |
Given two strings S and P. Find the smallest window in the string S consisting of all the characters(including duplicates) of the string P. Return "-1" in case there is no such window present. In case there are multiple such windows of same length, return the one with the least starting index.
Note : All characters ar... | class Solution:
def smallestWindow(self, s, p):
n = len(s)
if n < len(p):
return -1
m = [0] * 256
start = 0
ans = n + 1
cnt = 0
for i in p:
m[ord(i)] += 1
if m[ord(i)] == 1:
cnt += 1
i = 0
j ... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR V... |
Given two strings S and P. Find the smallest window in the string S consisting of all the characters(including duplicates) of the string P. Return "-1" in case there is no such window present. In case there are multiple such windows of same length, return the one with the least starting index.
Note : All characters ar... | class Solution:
def smallestWindow(self, s, c):
t_map = {}
for char in c:
if char in t_map:
t_map[char] += 1
else:
t_map[char] = 1
left = 0
right = 0
min_len = float("inf")
min_start = 0
char_needed = le... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR... |
Given two strings S and P. Find the smallest window in the string S consisting of all the characters(including duplicates) of the string P. Return "-1" in case there is no such window present. In case there are multiple such windows of same length, return the one with the least starting index.
Note : All characters ar... | class Solution:
def smallestWindow(self, s, p):
dict1 = {}
for i in range(len(p)):
dict1[p[i]] = 1 + dict1.get(p[i], 0)
ans = ""
mc = 0
dmc = len(p)
i = -1
j = -1
dict2 = {}
while True:
flag1 = 0
flag2 = 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 STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP ... |
Given two strings S and P. Find the smallest window in the string S consisting of all the characters(including duplicates) of the string P. Return "-1" in case there is no such window present. In case there are multiple such windows of same length, return the one with the least starting index.
Note : All characters ar... | class Solution:
def smallestWindow(self, s, p):
if p == "":
return ""
reslen = float("inf")
need = {}
for i in p:
need[i] = 1 + need.get(i, 0)
needCount = len(need)
window = {}
haveCount = 0
res = [-1, -1]
l = 0
... | CLASS_DEF FUNC_DEF IF VAR STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN V... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.