Maximize Weekly Workout Calories Without Back-to-Back Intense Days
Last updated: November 29, 2026
Quick Overview
Fitness+ suggests an intense workout plan where day i would burn calories[i], but the user cannot do intense workouts on two consecutive days. Return the maximum total calories achievable.
Apple
November 29, 20260
0
0 solved
Fitness+ suggests an intense workout plan where day i would burn calories[i], but the user cannot do intense workouts on two consecutive days. Return the maximum total calories achievable.
A gentle dynamic programming warm-up dressed in Apple Fitness+ terms, common in early screens. The interviewer checks that you define the state clearly and reduce space to O(1).
What the Interviewer Expects
- Define the recurrence best[i] = max(best[i-1], best[i-2] + calories[i])
- Handle zero, one and two days
- Reduce to two rolling variables
- Explain why greedy picking of the largest days fails
- Optionally reconstruct which days were chosen
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Return the chosen days, not just the total.
- The plan wraps around weekly, so day 7 and day 1 are also adjacent.
- Allow at most two intense days in a row instead of one.
- Some days are blocked by the user's calendar.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list of non-negative ints calories. Output: maximum sum of a subset with no two adjacent indices. Empty list gives 0....
High-Level Design
Let take be the best total that includes the current day and skip the best total that excludes it. Moving to day i, the new take is skip + calories[i] and the new skip is max(take, skip). ...