Link: https://leetcode.com/problems/spiral-matrix/
Solution:
Topics: simulation
Intuition
Fun little traversal problem! I remember doing this problem years ago and the code being incredibly long and bloated! But this time, having done many simulation problems like Walking robot simulation, I instantly knew how to implement this correctly. Also, most of the time I try to do cycle prevention in-place, rather than use a dedicated data structure. This came in handy here.
Implementation