PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates a candidate's ability to reason about grid-based movement and time-indexed reachability, testing competencies in algorithmic analysis, discrete geometry, and distance metrics.

  • hard
  • Zoox
  • Coding & Algorithms
  • Software Engineer

Can a Car Meet a Truck?

Company: Zoox

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Onsite

A truck's position on a 2D grid is known at each second. You are given an array `positions` where `positions[i] = [x_i, y_i]` is the truck's location at time `i + 1`. Another car starts at `(0, 0)` at time `0`. Every second, it may move one unit up, down, left, right, or stay in place. Return whether the car can occupy the same grid cell as the truck at the same time at any point. Example: - `positions = [[1, 0], [2, 0], [2, 1]]` - The answer is `true`, because the car can reach `(1, 0)` at time `1`. You should describe an efficient solution and handle edge cases carefully.

Quick Answer: This question evaluates a candidate's ability to reason about grid-based movement and time-indexed reachability, testing competencies in algorithmic analysis, discrete geometry, and distance metrics.

A truck's position on a 2D grid is known at each second. You are given an array `positions` where `positions[i] = [x_i, y_i]` is the truck's location at time `i + 1`. Another car starts at `(0, 0)` at time `0`. Every second the car may move one unit up, down, left, or right, or stay in place. Return `true` if the car can occupy the same grid cell as the truck at the same time at any point, and `false` otherwise. **Example:** - `positions = [[1, 0], [2, 0], [2, 1]]` - Output: `true` — the car can reach `(1, 0)` at time `1`. **Key insight:** At time `t = i + 1`, the car can be at any cell whose Manhattan distance from the origin is at most `t` (it can always burn extra moves by staying in place, so every distance `<= t` is reachable). Thus the answer is `true` iff there exists an index `i` with `|x_i| + |y_i| <= i + 1`.

Constraints

  • 1 <= positions.length <= 10^5 (the array may also be empty, in which case the answer is false)
  • positions[i].length == 2
  • -10^9 <= x_i, y_i <= 10^9
  • The car starts at (0, 0) at time 0 and may move 1 unit up/down/left/right or stay each second.

Examples

Input: ([[1, 0], [2, 0], [2, 1]],)

Expected Output: True

Explanation: At time 1 the car can reach (1, 0) since |1|+|0| = 1 <= 1, matching the truck's first position.

Input: ([[2, 0]],)

Expected Output: False

Explanation: At time 1 the truck is at (2, 0), but the car can be at most Manhattan distance 1 from the origin, so 2 > 1 — it cannot reach it.

Input: ([[1, 0]],)

Expected Output: True

Explanation: At time 1, |1|+|0| = 1 <= 1, so the car steps right to (1, 0) and meets the truck.

Input: ([],)

Expected Output: False

Explanation: There are no truck positions, so the car can never share a cell with it.

Input: ([[3, 0], [3, 0], [3, 0]],)

Expected Output: True

Explanation: At time 3 (index 2), |3|+|0| = 3 <= 3, so the car can be at (3, 0) by stepping right three times.

Input: ([[5, 5], [5, 5]],)

Expected Output: False

Explanation: The truck stays at Manhattan distance 10, but the car can reach distance at most 2 by time 2, so no meeting occurs.

Input: ([[-1, 0], [0, -2], [-2, -1]],)

Expected Output: True

Explanation: At time 1, |-1|+|0| = 1 <= 1, so the car can move to (-1, 0) and meet the truck immediately.

Input: ([[10, 10], [11, 0]],)

Expected Output: False

Explanation: Distance 20 at time 1 and distance 11 at time 2 both exceed the time elapsed, so the car can never catch up.

Hints

  1. What is the largest Manhattan distance the car can be from the origin after t seconds, given it moves at most one unit per second?
  2. Because the car can always stay in place to burn extra time, every cell with Manhattan distance <= t is reachable at time t — parity is not an obstacle.
  3. The truck is at positions[i] at time t = i + 1. The car can meet it there iff |x_i| + |y_i| <= i + 1. Scan once and check this condition.
  4. No BFS over the grid is needed; the reachable set at each second is exactly a Manhattan-distance ball, so a single linear pass with a closed-form check suffices.
Last updated: Jun 26, 2026

Loading coding console...

PracHub

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

Product

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

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL 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.

Related Coding Questions

  • Lane-Change Safety and Longitudinal Motion Simulation - Zoox (medium)
  • Compute Roller Coaster Scores - Zoox (medium)
  • Write Transaction Analytics SQL Queries - Zoox (medium)
  • Write SQL revenue and anomaly queries - Zoox (medium)
  • Choose fastest way to transfer 2 TB - Zoox (easy)