Last Truck to Leave the Lane
Updated
Problem statement
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[]) → doubleExamples
Example 1
laneLength = 10initial = [2,6]velocity = [2,-1]return = 6.0The 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