How Far Have You Gotten in Leet — (1)
1 min readDec 25, 2020
Description
Explanation
- The robot would be bounded in the circle if its position and direction get same with the initial while it perform the instructions in order.
- Expected that the robot would be heading one of the four directions - north, south, east, west- when a total order is given once.
- If the robot headed to the south, rotating 180 degree, then it should be back at the second repeat.
- If the east or the west, rotating 90 or 270 degree, then should be back at the fourth repeat at last.
- In other words, if the instructions repeat four times at last, we would know if the robot leaves the circle or not.
Solution
Review
I tried to solve this algorithmic way, using a queue and an array list to handle the sequential instructions, which got me in trouble. The key point of this problem is whether I was able to figure out the change of both position and direction at the same time. Dealing with it mathematically could be way easier.