Back to problems

Spiral Matrix (LC 54) with Follow-Up Constraints

Algorithm · ByteDance · Medium

You are given a matrix with m rows and n columns. Produce a list of all of its elements in the order you meet them when walking clockwise in a spiral, beginning at the top-left cell and working inward. The interviewer says at the outset that your code does not have to compile; what gets evaluated is whether the logic is correct. Follow-ups After a first solution that uses depth-first search with a visited array, two additional restrictions are introduced: You may not use a…

Loading the rest of the question…