1176. Diet Plan Performance
On This Page
class Solution:
def dietPlanPerformance(
self, calories: List[int], k: int, lower: int, upper: int
) -> int:
def check(s):
if s < lower:
return -1
if s > upper:
return 1
return 0
s, n = sum(calories[:k]), len(calories)
res = check(s)
for i in range(k, n):
s += calories[i] - calories[i - k]
res += check(s)
return res