Truck Refuel Distance With Extra Gas Stations

Asked at Amazon · Coding Questions · Difficulty: Medium

Trucks are parked at non-decreasing `position`. A gas station sits at `position[n-1]`. For each query `(a, b)`, two more gas stations are installed at `position[a-1]` and `position[b-1]` (1-based). Each truck drives forward to the nearest gas station at or beyond it to refuel; return, per query, the total distance driven by all trucks.

Loading the problem…