Problem · Array

Minimum Robot and Human Fulfillment Time

Learn this problem
MediumAmazon logoAmazonFULLTIMEOA
See Amazon hiring insights

Problem statement

An Amazon fulfillment center must process n orders. Order i must be assigned entirely to exactly one of two processing sides:

  • The automated robotics system processes all orders assigned to it in parallel. If it receives at least one order, its elapsed time is the maximum robotTime[i] among those orders.
  • The human workforce processes all orders assigned to it one by one. Its elapsed time is the sum of humanTime[i] across those orders.

The two sides work concurrently, so the elapsed time for an assignment is the maximum of the robotics-system time and the human-workforce time. For this exercise, an unused side contributes 0 hours.

Return the minimum possible elapsed time needed to process and dispatch every order.

Function

minimumFulfillmentTime(humanTime: long[], robotTime: long[]) → long

Examples

Example 1

humanTime = [9, 6, 8, 6, 4, 4]robotTime = [4, 3, 7, 7, 9, 8]return = 8

Assign the order with robotics time 9 and human time 4 to the human workforce, and assign every other order to the robotics system. The human side takes 4 hours, while the robot side takes 8 hours, so all orders finish in 8 hours.

No assignment can finish in 7 hours because both orders with robotics times above 7 would have to be handled by humans, requiring 4 + 4 = 8 hours.

Example 2

humanTime = [2, 3]robotTime = [10, 10]return = 5

Assign both orders to the human workforce. The human side takes 2 + 3 = 5 hours, and the unused robot side contributes 0 hours.

Constraints

  • 1 <= humanTime.length = robotTime.length <= 2 * 10^5
  • 1 <= humanTime[i], robotTime[i] <= 10^9
  • All sums and the returned result fit in a signed 64-bit integer.

More Amazon problems

drafts saved locally
public long minimumFulfillmentTime(long[] humanTime, long[] robotTime) {
    // Write your code here.
}
humanTime[9, 6, 8, 6, 4, 4]
robotTime[4, 3, 7, 7, 9, 8]
expected8
checking account