Solution: Diet Plan Performance
Let’s solve the Diet Plan Performance problem using the sliding window pattern.
We'll cover the following...
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 thanlower
, the dieter performs poorly and loses 1 point.If
T
is greater thanupper
, the dieter performs better and gains 1 point.If
T
is betweenlower
andupper
(inclusive), the dieter’s ...
Access this course and 1400+ top-rated courses and projects.