Count Convoys of Delivery Vans Arriving at a Shared Depot

Last updated: November 29, 2026

Quick Overview

Vans drive along one road toward a depot at a fixed mile marker, each with a start position and constant speed, and a faster van that catches a slower one ahead must slow down and travel with it. Return how many separate convoys reach the depot.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Vans drive along one road toward a depot at a fixed mile marker, each with a start position and constant speed, and a faster van that catches a slower one ahead must slow down and travel with it. Return how many separate convoys reach the depot.

A sorting-based greedy that fits Google Maps routing and logistics framing. The interviewer checks that you process vans from closest to the depot backward and compare arrival times instead of simulating motion.

What the Interviewer Expects
  • Sort vans by position descending
  • Compute each van's solo arrival time
  • Start a new convoy when a van arrives strictly later than the convoy ahead
  • Avoid step-by-step simulation
  • O(n log n) time
Key Topics to Cover
Greedy
Sorting
Monotonic stack
Simulation avoidance
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Return the size of each convoy.
  • Vans can overtake on a two-lane stretch for part of the route.
  • Report the time each convoy arrives.
  • Positions and speeds stream in; update the count incrementally.
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: target (depot marker), position list (distinct, below target), and speed list (positive). Vans cannot pass; a catch-up exactly at the depot counts as the same convoy. Output: number of co...

High-Level Design

The van closest to the depot is never slowed down, so it leads a convoy that arrives at (target - pos) / speed. Move backward through vans. A van that would arrive at or before the convoy ahead must...


Submit Your Answer
Markdown supported