Ctrl K

Assembly Line With No Waiting

Medium
A line has len(speeds) stations, and each of len(sizes) orders passes through all of them in turn, strictly in the order of the array sizes. Station i spends exactly speeds[i] · sizes[j] time units on order j. An order can never wait between stations: as soon as a station finishes, it hands the order to the next station, which must be free at that moment. A station handles only one order at a time. The first order starts at time 0. Return the earliest time at which the last station finishes the last order.
Example 1
speeds=[2, 1], sizes=[3, 1] → 10

Order 0: station 0 works from 0 to 6, station 1 from 6 to 9. Order 1 starts at 7: station 0 works from 7 to 9 and hands it over exactly when station 1 frees up, which finishes at 10.

Example 2
speeds=[3], sizes=[2, 5] → 21

With one station it is just 3·2 + 3·5 = 21.

Example 3
speeds=[1, 4, 2], sizes=[2, 3, 1] → 30
Constraints
  • 1 ≤ len(speeds), len(sizes) ≤ 5000
  • 1 ≤ speeds[i], sizes[j] ≤ 5000
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsShuttle Seat Plan MediumWho Refills the Coffee Beans MediumRunning Sum Waves MediumBack at the Dock EasyPump Rods at Their Peak Hard
loading Python…
Input
speeds=[2, 1], sizes=[3, 1]
Expected
10

Run checks the first 3 tests in your browser. Submit checks all 104 tests on the server, hidden ones included.