Minimum Time to Complete All Deliveries

You are given two integer arrays of size 2: d = [d1, d2] and r = [r1, r2].

Two delivery drones are tasked with completing a specific number of deliveries. Drone i must complete di deliveries.

Each delivery takes exactly one hour and only one drone can make a delivery at any given hour.

Additionally, both drones require recharging at specific intervals during which they cannot make deliveries. Drone i must recharge every ri hours, meaning at hours that are multiples of ri.

Return an integer denoting the minimum total time, in hours, required to complete all deliveries.

Example 1
Inputd = [3,1], r = [2,3]
Output5
The first drone can deliver at hours 1, 3, and 5 while the second drone delivers at hour 2, so all deliveries finish by hour 5.
Example 2
Inputd = [1,3], r = [2,2]
Output7
Both drones recharge at hours 2, 4, and 6, so one valid schedule finishes the first drone at hour 3 and the second drone at hours 1, 5, and 7.

Constraints

  • d = [d1, d2]
  • 1 <= di <= 10^9
  • r = [r1, r2]
  • 2 <= ri <= 3 * 10^4

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate