FastPrepMaximize Circular Rover Travel

Maximize Circular Rover Travel

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREEN
Learn

Problem statement

A circular route has length circumference. Each stops[i] = [position,fuel] has a distinct position. Choose any stop as the start and collect its fuel. Traveling one distance unit consumes one fuel.

Moving clockwise, collect each reached stop at most once. If fuel cannot reach the next uncollected stop, travel until fuel is exhausted. After collecting every stop, continue until remaining fuel is exhausted without collecting stops again. Return the maximum total distance traveled.

Function

maximumRoverDistance(circumference: int, stops: int[][]) → long

Examples

Example 1

circumference = 100stops = [[0,10],[10,30],[60,40]]return = 80

Start at 60, wrap to 0, then reach 10 and use the remaining fuel to stop at position 40 after 80 total distance.

Constraints

  • 1 <= stops.length <= 2000.
  • 0 <= position < circumference.
  • Fuel amounts are nonnegative.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public long maximumRoverDistance(int circumference, int[][] stops) {
  // Write your code here.
}
circumference100
stops[[0,10],[10,30],[60,40]]
expected80
Checking account…