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

Last Truck to Leave the Lane

Uber logoUber● MediumINTERNOA

Updated Sep 2026

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 Online Assessment questions

  • Count Palindromic Ancestor PathsOA · Seen Aug 2026
  • Jump Game with Prime-3 StepsOA · Seen Aug 2026
  • Chain of CommandOA · Seen Jul 2026
  • Total Palindrome Substring CostOA · Seen Jun 2026
  • Jump Game with Prime-Step RuleOA · Seen May 2026
  • Pipeline Throughput Maximization Under BudgetOA · Seen May 2026
  • Balanced Prefix Sets in a PermutationOA · Seen Apr 2026
  • Minimum Edge Reversals to Root a TreeOA · Seen Apr 2026
  • Maximum Riders in CarOA · Seen Apr 2026
  • Graph Palindrome QueriesOA · Seen Apr 2026

Similar questions at other companies

  • Bold Play to Reach a GoalSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Last Object Exit TimeIBM · OAIBM interview questions
  • Capping Portfolio WeightsCapstone Investment Advisors · OA
  • Repeated Mirror XORMathWorks · OAMathWorks interview questions
  • Stacked Item and Category DiscountsPalantir · OAPalantir interview questions
  • Find Total CostJP Morgan Chase · OAJP Morgan Chase interview questions
  • Macaron Order PriceOpenAI · OAOpenAI interview questions
  • Daily Settlement for Long and Short PositionsBelvedere Trading · OA
  • Debug the Risk-Limit QuoterMillennium · OAMillennium interview questions
  • Prime Factor VisitationMaven Securities · OAMaven Securities interview questions
All Uber interview questionsSee Uber hiring insights
Saved
class Solution {
    public double lastTruckExitTime(int laneLength, int[] initial, int[] velocity) {
      // write your code here
    }
}
Checking account…