Problem · Hash Table
Count Idle Warehouse Robots
Learn this problemProblem statement
The Amazon warehouse uses autonomous transport units positioned at distinct integer coordinates on a Cartesian plane. A transport unit at (x, y) is considered idle if there is at least one other unit strictly above it on the same vertical line, at least one strictly below it on the same vertical line, at least one strictly to its left on the same horizontal line, and at least one strictly to its right on the same horizontal line.
The neighboring units do not need to be immediately adjacent by distance 1. For example, a unit at (2, 3) has a unit directly above it if another unit exists at (2, y2) for some y2 > 3.
Given arrays x and y describing the coordinates of n transport units, return the number of idle units.
Function
numIdleDrives(x: int[], y: int[]) → intExamples
Example 1
x = [0, 0, 0, 0, 0, 1, 1, 1, 2, -1, -1, -2, -1]y = [-1, 0, 1, 2, -2, 0, 1, -1, 0, 1, -1, 0, 0]return = 5
The cartesian plane with idle robots marked red can be represented as:
The robots at locations (0, 0), (1, 0), (-1, -0), (0, 1), and (0, -1) are idle as they are surrounded by robots on all 4 sides.
Example 2
x = [1, 1, 1, 2, 2, 2, 2, 3, 3, 3]y = [1, 2, 3, 1, 2, 3, 5, 1, 2, 3]return = 2
The 10 robots are arranged as follows:
The robot at (2, 2) is idle because it has robots at (1, 2), (3, 2), (2, 3), and (2, 1) directly to the left, right, up, and down respectively.
The robot at (2, 3) is idle because it has robots at (1, 3), (3, 3), (2, 5), and (2, 2) directly to the left, right, up, and down respectively.
There are 2 idle robots in this arrangement.
Constraints
1 ≤ n ≤ 105-109 ≤ x[i], y[i] ≤ 109
More Amazon problems
- Resolve Task DependenciesONSITE INTERVIEW · Seen Jul 2026
- Shortest Distance on a Circular Bus RouteOA · Seen Jul 2026
- Longest Increasing Subsequence With Bounded Adjacent DifferenceONSITE INTERVIEW · Seen Jul 2026
- Search in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Jul 2026
- Sliding Window MaximumONSITE INTERVIEW · Seen Jul 2026
- Merge IntervalsOA · Seen Jul 2026
- Sort Bug Report FrequenciesOA · Seen Jul 2026
- Drone Delivery RouteOA · Seen Jul 2026