1176. Diet Plan Performance

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1176

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