All problems
0506EasyArrayTwo PointersBinary SearchGreedySorting

Forge and Kiln Booking

Tracked in this browser only
Write code

Trains the technique from

LeetCode 3633Earliest Finish Time for Land and Water Rides I

This 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.

Examples

Example 1

Input
forgeOpen = [8, 3], forgeLength = [5, 6], kilnOpen = [1, 7], kilnLength = [4, 2]
Output
11

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

Input
forgeOpen = [1], forgeLength = [1000], kilnOpen = [1000], kilnLength = [1]
Output
1002

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

Input
forgeOpen = [9, 1], forgeLength = [1, 30], kilnOpen = [4, 40], kilnLength = [1, 1]
Output
10

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.

Constraints

  • 1 <= forgeOpen.length == forgeLength.length <= 100
  • 1 <= kilnOpen.length == kilnLength.length <= 100
  • 1 <= forgeOpen[i], forgeLength[i], kilnOpen[j], kilnLength[j] <= 1000

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def earliest_both_done(forgeOpen: list[int], forgeLength: list[int], kilnOpen: list[int], kilnLength: list[int]) -> int:
Java
public int earliestBothDone(int[] forgeOpen, int[] forgeLength, int[] kilnOpen, int[] kilnLength)
September 7
Apply