Trains the technique from
LeetCode 3633Earliest Finish Time for Land and Water Rides IThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
An apprentice has to be signed off on exactly one forge session and exactly one kiln session before the day is over, and the two sessions may be taken in either order.
Forge session i unlocks at minute forgeOpen[i] and, once the apprentice begins it, occupies forgeLength[i] minutes without a break. Kiln session j unlocks at minute kilnOpen[j] and occupies kilnLength[j] minutes. A session may be begun at any minute at or after the minute it unlocks, and the apprentice may idle for as long as needed while waiting.
The apprentice is free from minute 0, cannot be in both workshops at the same time, and must finish one session before beginning the other. Return the earliest minute at which both chosen sessions can be finished.
Example 1
Forge session 1 unlocks at minute 3 and runs to minute 9. Kiln session 1 unlocks at minute 7, so it can begin at minute 9 and it runs to minute 11.
Example 2
The kiln session unlocks at minute 1000 and takes a single minute, ending at minute 1001. The forge session has been unlocked since minute 1, so it begins at minute 1001 and runs 1000 minutes to minute 2001.
Example 3
Kiln session 0 unlocks at minute 4 and takes 1 minute, ending at minute 5. Forge session 0 unlocks at minute 9, so it waits until minute 9 and takes 1 minute, ending at minute 10.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def earliest_both_done(forgeOpen: list[int], forgeLength: list[int], kilnOpen: list[int], kilnLength: list[int]) -> int:public int earliestBothDone(int[] forgeOpen, int[] forgeLength, int[] kilnOpen, int[] kilnLength)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.