FastPrepLast Truck to Leave the Lane
Problems/Last Truck to Leave the Lane

Last Truck to Leave the Lane

Uber logoUber● MediumINTERNOA
QuestionFunctionExamples

Problem statement

Source note: This problem is backed by a real Uber online assessment report. The report directly described the lane, signed velocities, boundary exits, velocity exchange on collision, and the final-time objective. It did not provide an exact return type, examples, input limits, precision rules, or zero-velocity behavior. The core task match is about 85%.

A lane is represented by the line segment from 0 to laneLength. Several trucks begin at distinct coordinates on the lane.

initial[i] is the starting coordinate of truck i, and velocity[i] is its signed velocity. A positive velocity moves a truck to the right, while a negative velocity moves it to the left.

When a truck crosses either boundary, it leaves the lane. When two trucks collide, they exchange their velocities and directions.

Return the time at which the last truck leaves the lane.

Function

lastTruckExitTime(laneLength: int, initial: int[], velocity: int[]) → double

Examples

Example 1

laneLength = 10initial = [2,6]velocity = [2,-1]return = 6.0

The trucks collide after 4/3 time units and exchange velocities. One truck then leaves through the right boundary at time 4, while the other leaves through the left boundary at time 6. Therefore, the last truck leaves at time 6.0.

More Uber problems

  • Worst-Performing Ads by CTR in a Campaign TreePHONE SCREEN · Seen Nov 2026
  • Earliest Time All Users Are ConnectedPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Max Points on a LinePHONE SCREEN · Seen Oct 2026
All Uber interview questionsSee Uber hiring insights
Saved
public double lastTruckExitTime(int laneLength, int[] initial, int[] velocity) {
  // write your code here
}
Checking account…