Spiral Matrix
Medium · Phone screen · Onsite · Full-time
Spiral matrix traversal from my RBC technical round. Return all elements of an m x n matrix in spiral order. The tricky part was the termination condition for non-square matrices where you can end up double-counting a row or column. The interviewer followed up asking how I'd generate a spiral matrix by filling in values 1 to n^2, which is basically the reverse operation.
