Skip to content

874. Walking Robot Simulation #475

Answered by topugit
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We need to simulate the robot's movement on an infinite 2D grid based on a sequence of commands and avoid obstacles if any. The goal is to determine the maximum Euclidean distance squared that the robot reaches from the origin.

Approach

  1. Direction Handling:

    • The robot can face one of four directions: North, East, South, and West.
    • We can represent these directions as vectors:
      • North: (0, 1)
      • East: (1, 0)
      • South: (0, -1)
      • West: (-1, 0)
  2. Turning:

    • A left turn (-2) will shift the direction counterclockwise by 90 degrees.
    • A right turn (-1) will shift the direction clockwise by 90 degrees.
  3. Movement:

    • For each move command, the robot will move in its current direction, one unit at a time. I…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@mah-shamim
Comment options

mah-shamim Sep 4, 2024
Maintainer Author

@topugit
Comment options

topugit Sep 4, 2024
Collaborator

Answer selected by mah-shamim
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants