← 返回 amazon 的题目列表Count Idle Robots with No Adjacent Robots in Four Directions
类型:online_judge
amazon
The warehouse can be represented in the form of a Cartesian plane, where robots are located at integral points of the form (x, y).
Consider a point (i, j), the nearest robot is likely to be sorted and chosen. It’s a point around which there will be other robots, and it will seldom be chosen for work. More formally, a robot is said to be idle if it has no robot located above, below, left, and right of it.
Example
Given the locations of robots, find the number of idle robots.
Input:
Two integer arrays x and y representing the x and y coordinates of the robots.
Output:
Return the number of idle robots.
x = [1, 1, 2, 2, 2, 2, 3, 3, 3, 3]
y = [1, 2, 2, 2, 2, 3, 3, 3, 3, 4]
Output: 1
Example
Input
[1, 1, 2, 2, 2, 2, 3, 3, 3, 3]
[1, 2, 2, 2, 2, 3, 3, 3, 3, 4]