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

Amazon Assessment Questions

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

亚马逊OA最新原题:Roomba形状的机器人。

题目描述

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. 

思路
初始化:使用四个哈希表分别记录每个x和y坐标的最小和最大值。
填充哈希表:遍历所有机器人位置,更新每个坐标的最小和最大值。
判断闲置:再次遍历机器人位置,检查每个机器人是否上下左右都有其他机器人,计数闲置机器人数量。
返回结果:输出闲置机器人数量。

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.

Code

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

最后,经过我们的强力面试辅助,OA代写,候选人通过这些面试题的解析和沟通,面试官不仅了解了候选人的编程能力,也看到了我在解决问题过程中清晰的思路和有效的沟通技巧。这些不仅有助于应对Amazon的面试,同时也能提升我们解决实际编程问题的能力。祝大家面试顺利!
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
azn7u2@163.com

Leave a Reply

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