AmazonOA #42
Get Number Idle Robots
Estimated EasyJudge-ready
Topics (AI-labelled)Hashing
A robot is idle if and only if at least one other robot lies strictly to its left and one strictly to its right in the same row, and one strictly above and one strictly below it in the same column. They do not need to be adjacent. Find the number of idle robots.
Input
The first line contains n (1..100000), followed by n lines of x y (−10⁹..10⁹). Robots at the same coordinates are counted separately, but they are not strict directional neighbors of each other.
Output
Output a single integer answer.
Example 1
Input:
9
0 0
1 0
2 0
0 1
1 1
2 1
0 2
1 2
2 2
Output:
1
Example 2
Input:
1
0 0
Output:
0
Example 3
Input:
5
0 0
-1 0
1 0
0 -1
0 1
Output:
1
Example notes
Example 1: in a 3×3 grid of points, only the center (1,1) has neighbors in all four directions, so the answer is 1. Example 2: there are no neighbors, so the answer is 0. Example 3: the center (0,0) of the cross is idle, while each of the other four points lacks a direction, so the answer is 1.
Editorial
Loading solution…