Amazon Assessment Questions: Roomba-shaped robots | 笔试代做

Amazon Assessment Questions

Latest original question for the Amazon Assessment Questions: Roomba-shaped robots .



Amazon 的机器人位于二维平面上的整数点(x, y)。如果一个机器人上下左右都有其他机器人,则该机器人是闲置的。给定n个机器人的位置,计算闲置机器人数量。

Amazon uses small, Roomba-shaped robots, called “Drives”. They deliver large stacks of products to human workers by following set paths around the warehouse. The warehouse can be represented in the form of a cartesian plane, where robots are located at integral points of the form (x, y). When a product is to be delivered to some point (i il the nearest robot is sought and chosen. Thus if a robot is surrounded by other robots nearby, it will seldom be chosen for work. More formally, a robot is said to be idle if it has a robot located above, below, left, and right of it. It is guaranteed that no two robots are at the same location. 


Initialization: Use four hash tables to record the minimum and maximum values of each x and y coordinate separately.
Fill hash table: Traverse all robot positions and update the minimum and maximum values of each coordinate.
Determine idle: Traverse the robot positions again, check if there are other robots up, down, left, right, and count the number of idle robots.
Return result: Output the number of idle robots.


def num_idle_drives(robot_positions):
    # 将机器人位置存储在集合中,方便查找
    robot_set = set(tuple(pos) for pos in robot_positions)
    idle_count = 0

    for x, y in robot_set:
        # 检查上下左右四个方向是否都有机器人
        if ((x+1, y) in robot_set and 
            (x-1, y) in robot_set and 
            (x, y+1) in robot_set and 
            (x, y-1) in robot_set):
            idle_count += 1
    return idle_count

# 示例使用
robot_positions = [(0, 0), (0, 1), (1, 0), (0, -1), (-1, 0), (2, 2)]
print(num_idle_drives(robot_positions))  # 输出:1

Learn More

StudyX Amazon Assessment Questions
Reddit Amazon OA

With our strong interview assistance and OA ghostwriting, the candidate not only understood their programming skills through the analysis and communication of these interview questions, but also saw my clear thinking and effective communication skills in problem-solving. These not only help us cope with Amazon interviews, but also enhance our ability to solve practical programming problems.


If you also need our interview assistance services, please contact us immediately.

author avatar

Leave a Reply

Your email address will not be published. Required fields are marked *