
Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
The robot only moves along the perimeter of the grid. Can you think if modulus can help you quickly compute which cell it stops at?
After the robot moves one time, whenever the robot stops at some cell, it will always face a specific direction. i.e., The direction it faces is determined by the cell it stops at.
Can you precompute what direction it faces when it stops at each cell along the perimeter, and reuse the results?