Lantern Crew Rest Planner
For each day, the crew can choose between a lower-intensity prep task and a higher-reward show task. The catch is that the show option cannot be used on back-to-back days, so a strong choice today can limit what is allowed tomorrow.
You are given two arrays, prep and show, where each index describes one day. On a day when you do not perform a show, you can still take the prep reward for that day.
For example, if prep = [2,2,2] and show = [3,3,3], the best total is 8. One good plan is to take a show on day 1, prep on day 2, and a show on day 3. That respects the rest rule and beats taking prep every day.
So the task is to build the highest-total schedule while making sure show days are never consecutive.
Example Input & Output
With no scheduled nights, the reward is zero.
A smart mix of work and rest can reach a best total of 8 tokens.
The best plan earns 15 tokens by thinking about the full schedule instead of only one day.
Algorithm Flow

Solution Approach
This is a small schedule DP where the important state is whether the previous day was a show day or not.
A convenient setup is to track two values for each day:
rest[i]: the best total up to day i if day i is not a show day
perform[i]: the best total up to day i if day i is a show day
If we do prep on day i, we can come from either state from the previous day:
If we do a show on day i, the previous day cannot also be a show day, so it must come from rest[i - 1]:
At the end, the answer is the larger of the two final states. This works because the only restriction we need to remember from one day to the next is whether yesterday was a show day.
Best Answers
import java.util.*;
class Solution {
public int calculate_max_crews(int[][] intervals) {
if (intervals.length == 0) return 0;
Arrays.sort(intervals, (a, b) -> a[1] - b[1]);
int count = 1;
int lastEnd = intervals[0][1];
for (int i = 1; i < intervals.length; i++) {
if (intervals[i][0] >= lastEnd) {
count++;
lastEnd = intervals[i][1];
}
}
return count;
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
