Code Logo

Lantern Crew Rest Planner

Published at05 Jan 2026
Hard 4 views
Like12

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

Example 1
Input
prep = [], show = []
Output
0
Explanation

With no scheduled nights, the reward is zero.

Example 2
Input
prep = [2,2,2], show = [3,3,3]
Output
8
Explanation

A smart mix of work and rest can reach a best total of 8 tokens.

Example 3
Input
prep = [3,2,4,2], show = [5,3,6,4]
Output
15
Explanation

The best plan earns 15 tokens by thinking about the full schedule instead of only one day.

Algorithm Flow

Recommendation Algorithm Flow for Lantern Crew Rest Planner
Recommendation Algorithm Flow for Lantern Crew Rest Planner

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:

rest[i] = Math.max(rest[i - 1], perform[i - 1]) + prep[i]

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]:

perform[i] = rest[i - 1] + show[i]

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

java
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;
    }
}