FastPrepLatest Arrival to Catch a Bus
Problems/Latest Arrival to Catch a Bus

Latest Arrival to Catch a Bus

Autodesk logoAutodesk● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report only names a catch-the-bus task. Latest-arrival selection, seat limits and boarding rules are practice assumptions; the original variant is unconfirmed. Approximate source match: 30%.

You are given bus departure times buses, existing passenger arrival times passengers, and the seat count capacity of each bus.

Buses depart in order of time. At each departure, up to capacity waiting passengers board in increasing arrival-time order. A passenger arriving exactly at departure may board. Passengers left behind wait for a later bus.

You want to join the queue. Choose a nonnegative integer arrival time different from every existing passenger arrival time. Return the latest time that lets you board any bus.

Times within each input array are distinct. The input arrays may be unsorted, and passengers may be empty. Your arrival joins the same boarding order. Do not change either input array.

Function

latestArrival(buses: int[], passengers: int[], capacity: int) → int

Examples

Example 1

buses = [10,20]passengers = [2,17,18,19]capacity = 2return = 16

The first bus takes arrival 2. The last bus fills with arrivals 17 and 18. Arriving at 16 gets a seat; 17, 18, and 19 are occupied times, while arriving at 20 leaves you behind.

Example 2

buses = [5,10]passengers = [1,2]capacity = 2return = 10

The first bus takes both existing passengers. The last bus has free seats, so arrival 10 is allowed.

Example 3

buses = [2]passengers = [1,2]capacity = 1return = 0

The bus has one seat. Arrival 1 is forbidden and arrival 2 is too late to get ahead of arrival 1. Arrival 0 gets the seat.

Constraints

  • 1 <= buses.length <= 10^5
  • 0 <= passengers.length <= 10^5
  • 1 <= buses[i] <= 10^9
  • 1 <= passengers[i] <= 10^9
  • 1 <= capacity <= 10^5
  • Bus departure times are distinct, and passenger arrival times are distinct.

More Autodesk interview questions

  • Diagonal Bounce TraversalOA · Seen Oct 2026
  • Interleave Array HalvesOA · Seen Oct 2026
  • Find Top Two TeamsOA · Seen Sep 2026
  • In-Memory Database with TTLOA · Seen Mar 2026
  • LRU Cache with TTLONSITE INTERVIEW · Seen Oct 2026
  • Deep Merge with a Conflict ResolverONSITE INTERVIEW · Seen Mar 2026

Similar questions at other companies

  • Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions
  • Minimum Removals to Balance ArraySalesforce · OASalesforce interview questions
  • Minimum Machines for TasksExpedia · OAExpedia interview questions
  • Find Minimum Possible SizeMathWorks · OAMathWorks interview questions
  • Minimum Days to Watch All MoviesAdobe · OAAdobe interview questions
  • Efficient Janitor TripsRoblox · OARoblox interview questions
  • Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Can Every Package Fit in a BoxIMC Trading · OAIMC Trading interview questions
  • Minimum Tunnel Crossing TimeArcesium · OAArcesium interview questions
  • Get Maximum PairsAmazon · OA

Interview reports that mention this question

  • Autodesk SDE Intern OA and Interviews: 5 Experiences
All Autodesk interview questionsSee Autodesk hiring insights
Saved
class Solution {
    public int latestArrival(int[] buses, int[] passengers, int capacity) {
        // write your code here
    }
}
Checking account…