Search⌘ K
AI Features

Solution: Diet Plan Performance

Explore how to apply the sliding window technique to solve the diet plan performance problem. Learn to efficiently calculate the sum of calories over k consecutive days, adjust performance points based on calorie thresholds, and implement a solution with O(n) time complexity and constant space usage.

Statement

A dieter consumes calories[i] calories on the i-th day.

Given an integer k, the dieter reviews their calorie intake over every sequence of k consecutive days (from calories[i] to calories[i+k-1] for all 0 <= i <= n-k). For each sequence, they calculate T, the total calories consumed over those k days:

  • If T is less than lower, the dieter ...