Reported July 2026
Uberbrainteaser

Last Truck to Leave the Lane

Reported by candidates from Uber's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Uber OA. Under 2s to a working solution.
Founder's read

The mistake that sinks a first attempt at this Uber OA, reported in July 2026, is simulating every collision. You sort the trucks, compute meeting times, swap velocities, and drown in edge cases. Don't. This is the classic ants-on-a-stick trick wearing a lane costume. Collisions swap velocities, so the set of motions on the lane never changes, only which truck owns which one. The answer is one pass and a max. If you blank while the OA clock is running, StealthCoder sits invisibly on your desktop as a safety net and surfaces the approach in real time. But you can write this one yourself in about five minutes once you see it.

The problem

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 = 10
initial = [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.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Treat each truck as a ghost that passes straight through every other truck. When two trucks swap velocities, the picture looks identical to two ghosts crossing. So the lane at any moment contains the same positions and velocities as the no-collision version. The last exit time is the max over all ghosts of their individual exit times. For a positive velocity, that's (laneLength - initial[i]) / velocity[i]. For a negative velocity, it's initial[i] / -velocity[i]. Check it on the example: the first truck gives (10-2)/2 = 4, the second gives 6/1 = 6, max is 6.0. That matches. The pitfall is building an event-queue simulation with floating point meeting times, which is slow, buggy, and unnecessary. Also watch your division and return a double, not an integer. Handle a zero velocity explicitly, since it never reaches a boundary. If the trick slips away mid-assessment, StealthCoder is the hedge that gets you to the one-liner fast. Complexity is O(n) time, O(1) space.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Last Truck to Leave the Lane cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Uber's OA.

Uber reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Last Truck to Leave the Lane FAQ

What's the trick in Last Truck to Leave the Lane?+

Ignore collisions. Since colliding trucks exchange velocities, you can pretend they pass through each other. Each truck's exit time is computed independently from its start and velocity, and the answer is the largest one. No sorting and no simulation needed.

How hard is this Uber OA question really?+

Easy to code, medium to see. The implementation is a loop and a max. The difficulty is resisting the urge to simulate collisions. If you've seen the ants-on-a-stick idea, it's a few minutes. If not, you'll burn most of your time on a doomed simulation.

Does swapping velocities, not just directions, break the pass-through argument?+

No. Swapping full signed velocities means the collection of (position, velocity) states is identical to two ghosts passing through each other. Speeds can differ and it still holds. The labels on the trucks change, but the set of exit times doesn't.

What edge cases should I test before submitting?+

Test the sample, giving 6.0. Test a single truck, all trucks moving right, and all moving left. Check a truck starting close to a boundary. Make sure you use floating point division and return a double. Decide how to treat zero velocity, since it never leaves the lane.

How do I prepare for this in 48 hours?+

Don't grind dozens of problems. Learn the pass-through idea for collisions, then write this solution from scratch twice. Spend the rest of your time on general array and math problems with floating point output. Pattern recognition on this type of problem is what the OA rewards.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Uber.

OA at Uber?
Invisible during screen share
Get it