description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Given an integer array arr of size N and an integer k, return the number of good subarrays of arr.
A good array is an array where the number of different integers in that is exactly k.
For example, {1, 3, 4, 4, 1} has 3 different integers: 1, 3, and 4.
Note : A subarray is a contiguous part of an array.
Example 1:
Inp... | class Solution:
def solve(self, arr, n, k):
d = {}
count, l, r = 0, 0, 0
while r < n:
if arr[r] not in d:
d[arr[r]] = 0
d[arr[r]] += 1
while len(d) > k:
if arr[l] not in d:
d[arr[l]] = 0
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR N... |
Given an integer array arr of size N and an integer k, return the number of good subarrays of arr.
A good array is an array where the number of different integers in that is exactly k.
For example, {1, 3, 4, 4, 1} has 3 different integers: 1, 3, and 4.
Note : A subarray is a contiguous part of an array.
Example 1:
Inp... | class Solution:
def helper(self, arr, N, k):
d = {}
j = 0
i = 0
count = 0
un = 0
while j < N:
if arr[j] in d:
d[arr[j]] = d[arr[j]] + 1
else:
d[arr[j]] = 1
un = un + 1
while un > k:
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR... |
Given an integer array arr of size N and an integer k, return the number of good subarrays of arr.
A good array is an array where the number of different integers in that is exactly k.
For example, {1, 3, 4, 4, 1} has 3 different integers: 1, 3, and 4.
Note : A subarray is a contiguous part of an array.
Example 1:
Inp... | class Solution:
def subarrayCount(self, arr, N, k):
def helper(k):
d = {}
i, j, ans = 0, 0, 0
while j < N:
d[arr[j]] = d.get(arr[j], 0) + 1
if len(d) > k:
while len(d) > k:
d[arr[i]] -= 1
... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER... |
Given an integer array arr of size N and an integer k, return the number of good subarrays of arr.
A good array is an array where the number of different integers in that is exactly k.
For example, {1, 3, 4, 4, 1} has 3 different integers: 1, 3, and 4.
Note : A subarray is a contiguous part of an array.
Example 1:
Inp... | class Solution:
def subarrayCount(self, arr, N, k):
return self.k_count(arr, N, k) - self.k_count(arr, N, k - 1)
def k_count(self, arr, N, k):
dic = dict()
i, j = 0, 0
cnt = 0
while j < N:
if arr[j] in dic:
dic[arr[j]] += 1
else:
... | CLASS_DEF FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMB... |
Given an integer array arr of size N and an integer k, return the number of good subarrays of arr.
A good array is an array where the number of different integers in that is exactly k.
For example, {1, 3, 4, 4, 1} has 3 different integers: 1, 3, and 4.
Note : A subarray is a contiguous part of an array.
Example 1:
Inp... | class Solution:
def subarrayCount(self, arr, N, k):
def total(count):
if count == 0:
return 0
res = 0
i = 0
c = 0
d = {}
for j in range(N):
if arr[j] not in d or d[arr[j]] == 0:
d[ar... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR ... |
Given an integer array arr of size N and an integer k, return the number of good subarrays of arr.
A good array is an array where the number of different integers in that is exactly k.
For example, {1, 3, 4, 4, 1} has 3 different integers: 1, 3, and 4.
Note : A subarray is a contiguous part of an array.
Example 1:
Inp... | class Solution:
def subarrayCount(self, s, N, k):
if k == 1:
n = len(s)
c = 1
f = 0
for i in range(n - 1):
if s[i] == s[i + 1]:
c += 1
else:
f += c * (c + 1) // 2
c = ... | CLASS_DEF FUNC_DEF IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN VAR ASSIGN VAR DICT... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
base = sum(c for c, g in zip(customers, grumpy) if g == 0)
ncus = [(c if g == 1 else 0) for c, g in zip(customers, grumpy)]
length = len(customers)
return base + max(sum(ncus[i : i + X]) ... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUM... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], k: int) -> int:
n = len(customers)
res = sum([(customers[i] * (1 - grumpy[i])) for i in range(n)])
best_gain = sum([(customers[i] * grumpy[i]) for i in range(k)])
gain = best_gain
for i in range(... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP NUMBER VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR BIN_OP V... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
t = 0
for i in range(len(grumpy)):
if grumpy[i] == 0:
t += customers[i]
customers[i] = 0
n = sum(customers[:X])
m = n
for i in range(1,... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR ... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, c: List[int], g: List[int], X: int) -> int:
arr = [0]
n = len(g)
for i in range(n):
arr.append(arr[-1] + (1 - g[i]) * c[i])
c = [0] + c
for i in range(n):
c[i + 1] = c[i] + c[i + 1]
m = -1
for i i... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASS... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
totalCusts = 0
for idx, custs in enumerate(customers):
if grumpy[idx] == 0:
totalCusts += customers[idx]
customers[idx] = 0
rollingSum = 0
maxS... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP VAR VAR VAR |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
old = 0
for i in range(len(customers)):
if grumpy[i] == 0:
old += customers[i]
l, r, res = 0, 0, 0
while r < len(customers):
if grumpy[r] == 1:
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR IF VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
max_satisfaction = sum(customers)
actual_satisfaction = sum(int(not g) * s for g, s in zip(grumpy, customers))
max_s_x = sum(customers[:X])
actual_s_x = sum(int(not g) * s for g, s in zip... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR FOR VA... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
mp = lp = sum(customers[i] for i in range(X) if grumpy[i])
mi = 0
for i in range(1, len(grumpy) - X + 1):
n = customers[i + X - 1] if grumpy[i + X - 1] else 0
o = customer... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR BIN... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
without_x = 0
for i, b in enumerate(grumpy):
if not b:
without_x += customers[i]
with_x = [0] * len(customers)
extra = 0
for i, b in enumerate(grumpy[:... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR ... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
grumpy, grum_sum, cus_sum = (
[(i ^ 1) for i in grumpy],
[0] * len(customers),
[0] * len(customers),
)
grumpy_customers = [(customers[i] * grumpy[i]) for i in ... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUM... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
satisfiedCustomers = 0
for i in range(len(customers)):
if grumpy[i] == 0:
satisfiedCustomers += customers[i]
customers[i] = 0
i = 0
unsatisfied... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
n = len(customers)
cnt = 0
acc = [0]
for i in range(n):
if grumpy[i]:
acc.append(acc[-1] + customers[i])
else:
acc.append(acc[-1])
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL ... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
if len(customers) <= X:
return sum(customers)
satisfied_customers = 0
current_unsatisfied_customers = 0
max_unsatisfied_customers = 0
for i in range(len(customers)):
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RE... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
lb, ub = 0, X - 1
total = sum([(customers[i] * (1 - grumpy[i])) for i in range(len(customers))])
saved = 0
for i in range(X):
if grumpy[i]:
saved += customers[... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP NUMBER VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN V... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
n, window_sum = len(customers), 0
for i in range(n):
if i < X:
window_sum += customers[i]
else:
window_sum += (1 - grumpy[i]) * customers[i]
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR IF VAR VAR NUMBER VAR VAR VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
satisfied = 0
for i in range(len(customers)):
satisfied += customers[i] * (grumpy[i] == 0)
p = X
best_imp = sum([customers[i] for i in range(p) if grumpy[i] == 1])
imp... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR IF VAR BIN_OP VAR VAR NUMBER VA... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
curr_running_delta = 0
max_delta = -(2**31), None
for i in range(len(customers)):
curr_running_delta += customers[i] * grumpy[i]
if i >= X - 1:
if curr_run... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER NONE FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
s = 0
for i in range(0, len(customers)):
if grumpy[i] == 0:
s += customers[i]
customers[i] = 0
tmp = [sum(customers[:X])]
for i in range(X, len... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR LIST BIN_OP BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR VAR RET... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
satisfied = 0
n = len(customers)
grumpySum = 0
for i in range(X):
satisfied += customers[i] if grumpy[i] == 0 else 0
saved = customers[i] if grumpy[i] == 1 else 0
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER A... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
satisfied = []
satisfied_before = 0
satisfied_after = sum(
[x[0] for x in zip(customers[X:], grumpy[X:]) if not x[1]]
)
for i in range(len(customers) - X + 1):
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR VAR ... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
already_happy = sum(c for c, h in zip(customers, grumpy) if not h)
running = sum(c for c, h in zip(customers[:X], grumpy[:X]) if h)
max_happy = running
for i in range(1, len(customers) - ... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER IF... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
L = len(grumpy)
if L == X:
return sum(customers)
grummpyCustomer = [(0 if grumpy[i] == 1 else customers[i]) for i in range(L)]
for i in range(1, L):
customers[i] +... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VA... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
satisfaction = 0
unsatisfied = []
for i in range(len(customers)):
if grumpy[i] == 1:
unsatisfied.append(customers[i])
else:
satisfaction +=... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
if not customers:
return 0
can_be_always_happy = X == len(customers)
customers_lost = [0] * (len(customers) + 1)
total_customers_lost = 0
total_satisfied = 0
f... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR IF VAR RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FO... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
wn = min(len(customers), X)
print(("wn", wn))
wList = [0] * len(customers)
for i in range(len(customers)):
if grumpy[i]:
wList[i] = customers[i]
el... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR STRING VAR ASSIGN VAR FUNC_CALL VAR VAR N... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
inital_sum = 0
tmp_sum = 0
res_sum = 0
length = len(customers)
for i in range(0, len(customers)):
if grumpy[i] == 0:
inital_sum += customers[i]
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
i = win_of_make_satisfied = satisfied = max_make_satisfied = 0
for c, g in zip(customers, grumpy):
satisfied += (1 - g) * c
win_of_make_satisfied += g * c
if i >= X:
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN BIN_OP VAR VAR VAR |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
gain = 0
for i in range(X):
if grumpy[i]:
gain += customers[i]
max_gain = gain
for i in range(X, len(customers)):
gain = gain + customers[i] * grum... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
saved = 0
max_saved = 0
sumTotal = 0
for i, value in enumerate(customers):
if i - X >= 0 and grumpy[i - X]:
saved -= customers[i - X]
if grumpy[i]:... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN BIN_OP VAR VAR VAR |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
curr = 0
max1 = 0
left = 0
for i in range(len(customers)):
if i < X:
curr += customers[i]
elif grumpy[i] == 0:
curr += customers[i]... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSI... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
satisfy = sum(cust for cust, grump in zip(customers, grumpy) if grump == 0)
max_extra = extra = sum(
cust for cust, grump in zip(customers[:X], grumpy[:X]) if grump == 1
)
sta... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
sums = 0
maxs = 0
for i in range(len(customers)):
sums += customers[i]
if grumpy[i] == 1:
grumpy[i] = customers[i]
sums -= grumpy[i]
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR RETURN BI... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
if X == len(customers):
return sum(customers)
sum_not_grumpy = sum(customers[:X])
sum_normal = sum([(x * (1 - y)) for x, y in zip(customers, grumpy)][X:])
max_customers = sum_... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR IF VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR BIN_... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
gains = [(x if grumpy[i] == 1 else 0) for i, x in enumerate(customers)]
fact = [(x if grumpy[i] == 0 else 0) for i, x in enumerate(customers)]
if X > len(gains):
return sum(customers)... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR ... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
base_count = 0
bonus_array = []
for i, j in zip(customers, grumpy):
if j == 0:
base_count += i
bonus_array.append(i * j)
bonus = 0
for i in... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR ASSIGN V... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
orig_satisfied_list = [
(customers[i] * (1 - grumpy[i])) for i in range(len(customers))
]
orig_satisfied = sum(orig_satisfied_list)
grumpy_satisfied_list = [
(cust... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP NUMBER VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN ... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
n = len(customers)
sum_cus = sum(customers)
for i in range(n):
customers[i] *= grumpy[i]
window = 0
max_secret_satisfied = -math.inf
left, right = 0, 0
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER WHILE BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER R... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
total = 0
for i in range(len(customers)):
total += (1 - grumpy[i]) * customers[i]
grumpy[i] *= customers[i]
maxsum = 0
for i in range(X):
maxsum += gru... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR A... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
if X > len(customers):
return sum(customers)
sum1 = [customers[0]]
sum2 = []
if grumpy[0] == 0:
sum2.append(customers[0])
else:
sum2.append(0)
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR IF VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR NUMBER E... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
N = len(customers)
satisfy = 0
unsatisfied = []
max_value = 0
if not customers:
return []
elif not grumpy or N == 1:
return sum(customers)
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER IF VAR RETURN LIST IF VAR VAR NUMBER RETURN FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP ... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
zeroTotal = 0
for i in range(len(customers)):
if grumpy[i] == 0:
zeroTotal += customers[i]
q = deque()
oneTotal = 0
largest = 0
for i in range(... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER WHILE VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR FUNC_CALL VAR NUMBER EXPR F... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
n = len(grumpy)
if X >= n:
return sum(customers)
init = sum([(customers[i] * (1 - grumpy[i])) for i in range(n)])
for j in range(X):
if grumpy[j] == 1:
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP NUMBER VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
if len(customers) == X:
return sum(customers)
maxLoss = 0
total = sum([(customers[i] * (1 - grumpy[i])) for i in range(len(grumpy))])
print(total)
loss = sum([(grumpy[... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP NUMBER VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | import itertools as it
class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
self.customers = customers
self.grumpy = grumpy
self.n = len(customers)
self.cumulative_customers = list(it.accumulate(customers, initial=0))
self.techniq... | IMPORT CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR RETURN FUNC_CALL VAR NUMBER NUMBER VAR FUNC_DEF VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER RETURN BIN_OP ... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
window, max_window = 0, 0
for i in range(X):
if grumpy[i]:
window += customers[i]
max_window = window
for i in range(X, len(grumpy)):
if grumpy[i -... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL ... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
to_ret = sum([c for c, g in zip(customers, grumpy) if g == 0])
mt = mf = sum([c for c, g in zip(customers[:X], grumpy[:X]) if g == 1])
for t in range(X, len(customers)):
if grumpy[t] ... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR IF VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR ASS... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, A: List[int], G: List[int], X: int) -> int:
res = 0
s = 0
ws = 0
left = []
for i in range(len(A)):
c, g = A[i], G[i]
s += (1 - g) * c
ws += g * c
if i >= X:
ws -= A[i - X] ... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
gc = []
l = len(customers)
for i in range(l):
gc.append(customers[i] * grumpy[i])
ms = 0
mi = -1
for i in range(l - X + 1):
s = sum(gc[i : i + X])
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN ... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
n = len(customers)
start = 0
curSatisfaction = sum(customers[i] for i in range(n) if grumpy[i] == 0)
maxSatisfaction = 0
for end in range(len(customers)):
if grumpy[en... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
curr_sum = sum([(i * abs(j - 1)) for i, j in zip(customers, grumpy)])
max_sum = curr_sum
for i in range(X):
curr_sum += customers[i] * grumpy[i]
max_sum = max(max_sum, cur... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
if X == len(customers):
return sum(customers)
for i in range(len(grumpy)):
grumpy[i] = 0 if grumpy[i] == 1 else 1
mults = [(x * y) for x, y in zip(customers, grumpy)]
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR IF VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BI... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
happy_owner_cust = 0
for pos in range(len(customers)):
if grumpy[pos] == 0:
happy_owner_cust += customers[pos]
customers[pos] = 0
calming_owner_cust = ... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP VA... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
start = 0
end = X
ans = 0
for i in range(len(grumpy)):
if grumpy[i] == 0:
ans += customers[i]
t = 0
for i in range(X):
if grumpy[i]... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
n = len(customers)
res = 0
for k in range(len(customers)):
if grumpy[k] == 0:
res = res + customers[k]
diff = []
for j in range(len(customers)):
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP B... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
ans = 0
L = len(grumpy)
if X >= L:
return sum(customers)
for i in range(L):
if grumpy[i] == 0:
ans += customers[i]
res = cur_sum = 0
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER V... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
N = len(grumpy)
already_happy = sum(customers[i] for i in range(N) if not grumpy[i])
window = sum(customers[i] for i in range(X) if grumpy[i])
max_bonus = window
for r in range(X,... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER ASSIG... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
disSatisfy = [(c * g) for c, g in zip(customers, grumpy)]
start = 0
grumpy_num = 0
for i in range(X):
grumpy_num += disSatisfy[i]
remaining = grumpy_num
for j ... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
window = [0] * X
for a in range(X):
if grumpy[a] == 1:
window[a] += customers[a]
mySum = 0
maxAdded = sum(window)
right = X
for i in range(len(... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
no_tech = [0] * len(customers)
tech = [0] * len(customers)
if len(customers) <= X:
return sum(customers)
if not grumpy[0]:
no_tech[0] = customers[0]
tech[0... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR ASSIG... |
Today, the bookstore owner has a store open for customers.length minutes. Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on the i-th minute, grumpy[i] = ... | class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:
satisfied = 0
for i in range(len(grumpy)):
if grumpy[i] == 0:
satisfied += customers[i]
windowMax = 0
curr = 0
for i in range(len(customers)):
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR V... |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def totalFruit(self, tree: List[int]) -> int:
q = []
ans = -99999999999
s = 0
e = s
while e < len(tree):
if tree[e] not in q:
if len(q) < 2:
q.append(tree[e])
else:
if e - s >... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR ... |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def totalFruit(self, tree: List[int]) -> int:
fruit_dict = collections.defaultdict(int)
j, result, count = 0, 0, 0
for i, t in enumerate(tree):
fruit_dict[t] += 1
count += 1
while len(fruit_dict) > 2 and j < len(tree):
frui... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR F... |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def totalFruit(self, tree):
ans = cur = one = two = count_one = count_two = 0
for i in tree:
if i not in (one, two):
cur = count_two + 1
else:
cur += 1
if i != two:
one, two = two, i
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def totalFruit(self, tree: List[int]) -> int:
blocks = []
i = 0
while i < len(tree):
j = i + 1
length = 1
while j < len(tree) and tree[j] == tree[j - 1]:
length += 1
j += 1
blocks.append((tree[i]... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VA... |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def totalFruit(self, trees: List[int]) -> int:
if len(trees) <= 2:
return len(trees)
lp = 0
rp = 1
maxSize = 0
hash = collections.defaultdict(int)
lpInc = False
rpInc = False
curSet = set()
hash[trees[lp]] += 1
... | CLASS_DEF FUNC_DEF VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR WHIL... |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def totalFruit(self, tree: List[int]) -> int:
res = []
ind = 0
if len(tree) == 1:
return 1
if len(set(tree)) <= 2:
return len(tree)
while ind < len(tree) - 1:
count = 0
types = set()
for i in range(i... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VA... |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def totalFruit(self, tree: List[int]) -> int:
current_picking = tree[0]
prev_picking = None
max_picked = 0
baskets = {current_picking: [0, 0]}
for i in range(len(tree)):
if tree[i] != current_picking:
if len(baskets) < 2:
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NONE ASSIGN VAR NUMBER ASSIGN VAR DICT VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR LIST VAR VAR IF VAR V... |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def totalFruit(self, tree: List[int]) -> int:
grp = []
x, y = tree[0], 1
for e in tree[1:]:
if e == x:
y += 1
else:
grp.append((x, y))
x, y = e, 1
grp.append((x, y))
ret = 0
pair,... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR VAR NUMBER NUMBER FOR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR LIST NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR VAR ... |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def totalFruit(self, tree: List[int]) -> int:
prev_count = curr = count_b = result = 0
a = None
b = None
for c in tree:
if b == c:
curr += 1
count_b += 1
elif a == c:
curr += 1
co... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR NONE ASSIGN VAR NONE FOR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL... |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def totalFruit(self, tree: List[int]) -> int:
blocks = []
i = 0
while i < len(tree):
start = i
while i + 1 < len(tree) and tree[i + 1] == tree[start]:
i += 1
blocks.append((tree[start], i - start + 1))
i = i + 1... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FU... |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def totalFruit(self, tree: List[int]) -> int:
l = 0
count = {}
for r, value in enumerate(tree):
count[value] = count.get(value, 0) + 1
if len(count) > 2:
count[tree[l]] -= 1
if count[tree[l]] == 0:
d... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER VAR |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def totalFruit(self, tree: List[int]) -> int:
count = collections.Counter()
i = ans = 0
for j in range(len(tree)):
fruit = tree[j]
count[fruit] += 1
while len(count.keys()) > 2:
count[tree[i]] -= 1
if count[... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER WHILE FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VA... |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def totalFruit(self, tree: List[int]) -> int:
left = 0
n = len(tree)
ans = 0
basket = set()
counter = collections.Counter()
for right, fruit in enumerate(tree):
basket.add(fruit)
counter[fruit] += 1
while len(basket... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ... |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def totalFruit(self, tree: List[int]) -> int:
if not tree:
return 0
l = 0
mp = collections.defaultdict(int)
fruits = 1
for i in range(0, len(tree)):
mp[tree[i]] += 1
while len(mp) > 2:
mp[tree[l]] -= 1
... | CLASS_DEF FUNC_DEF VAR VAR IF VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR... |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def totalFruit(self, tree: List[int]) -> int:
fruitCap = [0] * len(tree)
fruitCap[-1] = 1
fruitA = tree[-1]
fruitB = None
for i in reversed(list(range(len(tree) - 1))):
if tree[i] == fruitA or tree[i] == fruitB:
fruitCap[i] = fruit... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NONE FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR NONE ASSIGN VAR... |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def totalFruit(self, tree: List[int]) -> int:
insp = {}
pos = {}
mxx = -1
i = 0
while i < len(tree):
f = tree[i]
if f not in insp and len(insp) == 2:
mnn = math.inf
tod = None
for of, op ... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NONE FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR V... |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def totalFruit(self, tree: List[int]) -> int:
ans, j = 0, 0
n = len(tree)
dic = {}
for i in range(n):
dic[tree[i]] = i
if len(dic) > 2:
ans = max(ans, i - j)
k = None
for key in dic:
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR NONE FOR VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN... |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def totalFruit(self, tree: List[int]) -> int:
n = len(tree)
dic = {}
x = 0
for i in range(n):
if tree[i] not in dic.keys():
dic[tree[i]] = 1
else:
dic[tree[i]] += 1
if len(dic) > 2:
d... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER VAR |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def totalFruit(self, tree: List[int]) -> int:
i = 0
counter = {}
res = 0
for j, v in enumerate(tree):
counter[v] = counter.get(v, 0) + 1
while len(counter) > 2:
counter[tree[i]] -= 1
if not counter[tree[i]]:
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR ... |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def totalFruit(self, tree: List[int]) -> int:
if len(tree) == 1:
return 1
window_start = 0
window_end = 2
total_max = 2
if tree[0] == tree[1]:
tmp_index = 0
else:
tmp_index = 1
fruit_type = set(tree[:2])
... | CLASS_DEF FUNC_DEF VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF... |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def totalFruit(self, tree: List[int]) -> int:
start = 0
max = 0
reset = 0
baskets = {(1): [None, 0], (2): [None, 0]}
while start < len(tree) and start >= 0:
if baskets[1][0] == None:
baskets[1][0] = tree[start]
bask... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER LIST NONE NUMBER LIST NONE NUMBER WHILE VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER NUMBER NONE ASSIGN VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR VAR NUMBER IF VAR NUMBER NUMBER VAR BIN_OP... |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def totalFruit(self, tree: List[int]) -> int:
blocks = [(k, len(list(v))) for k, v in itertools.groupby(tree)]
i, result = 0, 0
while i < len(blocks):
j = i
count = 0
fruit_set = set()
while j < len(blocks):
fru... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUM... |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def totalFruit(self, tree: List[int]) -> int:
maxCount = count = 0
head = back = 0
buckets = dict()
while back < len(tree):
fruit = tree[back]
if fruit in buckets:
buckets[fruit] += 1
else:
buckets[f... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER WHILE FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR... |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def totalFruit(self, tree: List[int]) -> int:
compressedTree = []
current = [tree[0], 0]
for index in range(len(tree)):
fruit = tree[index]
if fruit != current[0]:
compressedTree.append(current)
current = [fruit, 1]
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL ... |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def totalFruit(self, tree: List[int]) -> int:
i = 0
count = collections.Counter()
for index, value in enumerate(tree):
count[value] += 1
if len(count) > 2:
count[tree[i]] -= 1
if count[tree[i]] == 0:
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR VAR VAR |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def totalFruit(self, tree) -> int:
n = len(tree)
if n <= 2:
return n
tem = collections.Counter()
res = 0
i = 0
j = 1
tem.update(tree[:1])
while j < n:
while j < n and len(tem.keys()) <= 2:
tem.up... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER WHILE VAR VAR WHILE VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR... |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def totalFruit(self, tree: List[int]) -> int:
if len(tree) == 1:
return 1
l = 0
r = 1
curr_window = defaultdict(int)
curr_window[tree[l]] += 1
res = 1
while r < len(tree):
curr_window[tree[r]] += 1
while len... | CLASS_DEF FUNC_DEF VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF BIN_... |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def atMostK(self, nums, K):
counter = collections.Counter()
res = i = 0
for j in range(len(nums)):
if counter[nums[j]] == 0:
K -= 1
counter[nums[j]] += 1
while K < 0:
counter[nums[i]] -= 1
if... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR FUNC_DEF VAR ... |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def totalFruit(self, tree: List[int]) -> int:
res = 0
mres = 0
temp = set()
i = 0
newidx = 0
while i < len(tree):
if len(temp) == 0:
mres += 1
temp.add(tree[i])
i += 1
elif len(te... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER... |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def totalFruit(self, tree: List[int]) -> int:
max_ = 0
baskets = {}
def get_other_tree(this_tree):
trees = list(baskets.keys())
return trees[1 - trees.index(this_tree)] if len(trees) == 2 else trees[0]
for idx, tr in enumerate(tree):
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR NUMBER VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CAL... |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def totalFruit(self, tree: List[int]) -> int:
if len(set(tree)) <= 2:
return len(tree)
types = set()
maxFruits = 0
for i in range(len(tree)):
start = i
res = 0
types = set()
for i in range(start, len(tree)):... | CLASS_DEF FUNC_DEF VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR N... |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def totalFruit(self, tree: List[int]) -> int:
type_cnt = {}
max_fruit = -1
left_ptr = 0
last_cnt = 0
while left_ptr < len(tree):
right_ptr = left_ptr
while right_ptr < len(tree) - 1 and tree[right_ptr] == tree[right_ptr + 1]:
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR ... |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def totalFruit(self, ar: List[int]) -> int:
l = list(set(ar))
if len(l) <= 2:
return len(ar)
else:
m = 0
for i in range(0, len(ar)):
l = [ar[i]]
d = 1
for j in range(i + 1, len(ar)):
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VA... |
In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit from this tree to your baskets. If you cannot, stop.
Move to the next tree to the right of the current tree. If there is no tree to the right, s... | class Solution:
def totalFruit(self, tree: List[int]) -> int:
total_fruits = collections.defaultdict(int)
unique_baskets = 0
max_fruit_types = 0
start = 0
for end in range(len(tree)):
cur_fruit = tree[end]
total_fruits[cur_fruit] += 1
if t... | 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 FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VA... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.