Skip to content

Instantly share code, notes, and snippets.

@brianspiering
Last active December 15, 2021 12:21
Show Gist options
  • Save brianspiering/9562bf3dc63501e8194b5ef35d429608 to your computer and use it in GitHub Desktop.
Save brianspiering/9562bf3dc63501e8194b5ef35d429608 to your computer and use it in GitHub Desktop.
Homeward Bound Robot Problem

Problem Statement

A robot starts at position (0, 0). Given a sequence of its moves, judge if this robot makes a complete trip. A complete trip means the robot ends back at the original location.

The valid robot moves are "R" (Right), "L" (Left), "U" (Up) and "D" (down). For example, a sequence of moves could be "RRLUUD". The robot would move:

  • Move 1 unit to the right
  • Move another 1 unit to the right
  • Move 1 unit to the left
  • Move 1 unit up
  • Move another 1 unit up
  • Move 1 unit down

Common Questions

  • Q: How big is the grid?
    • A: It does not matter. Assume there is a fixed number of commands received by the robot. But the world is not bounded.
  • Q: Can I import anything from Python's Standard Library?
    • A: No, No imports allowed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment