FastPrepMaximum Value for Two Delivery Robots
Problems/Maximum Value for Two Delivery Robots

Maximum Value for Two Delivery Robots

Nuro logoNuro● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The source defines two non-overlapping contiguous robot routes and gives one sample, but omits whether capacities are exact and whether the robots have a fixed street order. The judged core task matches the visible source at about 93%.

Houses lie in a row, and values[i] is the delivery value at house i. Two robots must serve non-overlapping contiguous segments of houses.

For this exercise, assume the first robot serves exactly c1 consecutive houses and the second robot serves exactly c2 consecutive houses. Either robot's segment may appear first along the street.

Return the maximum total value served by the two robots.

Function

maxDeliveryValue(values: int[], c1: int, c2: int) → long

Examples

Example 1

values = [4,2,3,5]c1 = 2c2 = 1return = 12

The second robot serves the first house for value 4. The first robot serves the final two houses for value 3 + 5 = 8. The segments do not overlap, and their total value is 12.

Example 2

values = [1,2,3,4,5]c1 = 2c2 = 2return = 14

The robots can serve [2,3] and [4,5]. Their total is 5 + 9 = 14.

Example 3

values = [5,1,1,5]c1 = 1c2 = 1return = 10

Each robot serves one of the two houses with value 5, for a total of 10.

Constraints

  • 2 <= values.length <= 200000
  • 0 <= values[i] <= 10^9
  • 1 <= c1 and 1 <= c2
  • c1 + c2 <= values.length
  • The answer fits in a signed 64-bit integer.

More Nuro problems

  • Merge Timestamped Record ListsPHONE SCREEN · Seen Oct 2026
  • Assign Robots to Their Nearest Available ItemsPHONE SCREEN · Seen Oct 2026
  • Container With Most WaterPHONE SCREEN · Seen Oct 2026
All Nuro interview questionsSee Nuro hiring insights
Saved
class Solution {
    public long maxDeliveryValue(int[] values, int c1, int c2) {
        // Write your code here.
    }
}
Checking account…