Spiral Matrix IV
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given two integers m and n, the number of rows and columns of a grid, and the head of a linked list of non-negative integers.
Write the list's values into the grid in **clockwise spiral order**: start at the top-left cell moving right along the top row, turn down at the right edge, then left along the bottom, then up, spiraling inward and never revisiting a cell. Fill cells in that order until the list is exhausted.
Any cells that receive no value hold -1. Return the m x n grid as a list of rows. The list never has more than m * n nodes.
Examples
Constraints
- 1 <= m, n <= 10^5
- 1 <= m * n <= 10^5
- 1 <= number of nodes <= m * n
- 0 <= Node.val <= 1000
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.