Check if given set of moves is circular or not

A rover is given instructions such as Move (M), Left (L) and Right (R). Check if given set of moves is circular or not. If circular return true, otherwise return false. The move is circular if its starting and ending coordinates are the same. The moves contain instructions to move one unit in same direction (M), to change direction to left of current direction (L) and to change direction to right of current direction (R).

Example Solution

Imagine the rover given the set of moves MRMRMRM. The robot will execute the orders in sequence:

  • Move 1 Unit
  • Turn Right
  • Move 1 Unit
  • Turn Right
  • Move 1 Unit
  • Turn Right
  • Move 1 Unit

After the last instruction, the robot will arrive at the original position. So the program should return true.

Contributed by Murat Sütunç