How Far Have You Gotten in Leet — (1)

Minho Jang
1 min readDec 25, 2020

--

Description

resource link : LeetCode

Explanation

  1. 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.
  2. Expected that the robot would be heading one of the four directions - north, south, east, west- when a total order is given once.
  3. If the robot headed to the south, rotating 180 degree, then it should be back at the second repeat.
  4. If the east or the west, rotating 90 or 270 degree, then should be back at the fourth repeat at last.
  5. 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.

--

--

Minho Jang
Minho Jang

Written by Minho Jang

Backend Developer, Writer, and Lifelong Learner

No responses yet