PracHub
QuestionsCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Uber

Last Truck to Leave a One-Dimensional Lane

Last updated: Jul 21, 2026

Quick Overview

This algorithms interview question evaluates reasoning about continuous motion, collisions, and exact rational time in a one-dimensional simulation. It is commonly asked to assess whether an engineer can distinguish physical behavior from identity semantics while handling large inputs and precise boundary conditions.

  • medium
  • Uber
  • Coding & Algorithms
  • Software Engineer

Last Truck to Leave a One-Dimensional Lane

Company: Uber

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Take-home Project

# Last Truck to Leave a One-Dimensional Lane Implement `last_exit_time(lane_length, positions, velocities)`. Distinct trucks start at integer positions strictly between `0` and `lane_length`. Truck `i` moves continuously at constant nonzero integer velocity `velocities[i]`: positive is right, negative is left. A truck leaves as soon as it crosses either boundary. When two trucks meet, they instantaneously exchange velocities. Trucks have zero length, and the input excludes simultaneous collisions involving three or more trucks. Return the time when the final truck leaves as a reduced fraction `(numerator, denominator)` with a positive denominator. ## Constraints - `1 <= lane_length <= 10^9` - `1 <= len(positions) == len(velocities) <= 200,000` - Initial positions are distinct. - `1 <= abs(velocities[i]) <= 10^9` - Every truck initially moves toward one of the two boundaries. ## Example behavior A truck at position `3` moving left at speed `2` would reach the left boundary after `3/2` time units if no label-changing collision affected its identity. ## Candidate clarifications Confirm collision physics, whether truck identity matters to the requested final time, boundary semantics, and the required exact representation.

Quick Answer: This algorithms interview question evaluates reasoning about continuous motion, collisions, and exact rational time in a one-dimensional simulation. It is commonly asked to assess whether an engineer can distinguish physical behavior from identity semantics while handling large inputs and precise boundary conditions.

Related Interview Questions

  • Kth Employee Reached in an Ordered Hierarchy - Uber (medium)
  • Minimum Delivery Cost Between Cities - Uber (medium)
  • Thread-Safe Token-Bucket Rate Limiter - Uber (medium)
  • Quadtree for 2D Geospatial Points - Uber (medium)
|Home/Coding & Algorithms/Uber

Last Truck to Leave a One-Dimensional Lane

Uber logo
Uber
Jul 3, 2026, 12:00 AM
mediumSoftware EngineerTake-home ProjectCoding & Algorithms
3
0

Last Truck to Leave a One-Dimensional Lane

Implement last_exit_time(lane_length, positions, velocities).

Distinct trucks start at integer positions strictly between 0 and lane_length. Truck i moves continuously at constant nonzero integer velocity velocities[i]: positive is right, negative is left. A truck leaves as soon as it crosses either boundary. When two trucks meet, they instantaneously exchange velocities. Trucks have zero length, and the input excludes simultaneous collisions involving three or more trucks.

Return the time when the final truck leaves as a reduced fraction (numerator, denominator) with a positive denominator.

Constraints

  • 1 <= lane_length <= 10^9
  • 1 <= len(positions) == len(velocities) <= 200,000
  • Initial positions are distinct.
  • 1 <= abs(velocities[i]) <= 10^9
  • Every truck initially moves toward one of the two boundaries.

Example behavior

A truck at position 3 moving left at speed 2 would reach the left boundary after 3/2 time units if no label-changing collision affected its identity.

Candidate clarifications

Confirm collision physics, whether truck identity matters to the requested final time, boundary semantics, and the required exact representation.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Uber•More Software Engineer•Uber Software Engineer•Uber Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.