Can a Car Meet a Truck?
Problem Description
A truck's movement is tracked on a 2D grid. You are provided with an array positions, where positions[i] = [x_i, y_i] represents the truck's exact location at time i + 1 seconds.
A separate car begins its journey at coordinates (0, 0) at time 0 seconds. Each second, the car has the flexibility to move one unit in any of the four cardinal directions (up, down, left, right) or to remain stationary in its current cell.
Task
Determine whether the car can ever reach the same grid cell as the truck at the exact same moment in time. Your solution should be efficient and robustly handle various edge cases.
Example
positions = [[1, 0], [2, 0], [2, 1]]- Output:
true- Explanation: The car starts at
(0,0)att=0. Att=1, the truck is at(1,0). The car can move one unit right to(1,0)and meet the truck att=1.
- Explanation: The car starts at
AI interview prep
Core dilemma
Efficiently determining if a point in a time-series path is reachable by a constrained-movement entity within the given time, balancing algorithmic simplicity with scalability for large inputs.
2 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Can a Car Meet a Truck?
Problem Description
A truck's movement is tracked on a 2D grid. You are provided with an array positions, where positions[i] = [x_i, y_i] represents the truck's exact location at time i + 1 seconds.
A separate car begins its journey at coordinates (0, 0) at time 0 seconds. Each second, the car has the flexibility to move one unit in any of the four cardinal directions (up, down, left, right) or to remain stationary in its current cell.
Task
Determine whether the car can ever reach the same grid cell as the truck at the exact same moment in time. Your solution should be efficient and robustly handle various edge cases.
Example
positions = [[1, 0], [2, 0], [2, 1]]- Output:
true- Explanation: The car starts at
(0,0)att=0. Att=1, the truck is at(1,0). The car can move one unit right to(1,0)and meet the truck att=1.
- Explanation: The car starts at