Complete the code to initialize the starting row index for spiral traversal.
let mut top = [1];The top row index starts at 0 because matrix rows are zero-indexed.
Complete the code to initialize the ending column index for spiral traversal.
let mut right = [1] - 1;
The right column index is the number of columns minus one, so we use matrix[0].len() - 1.
Fix the error in the loop condition to continue spiral traversal while boundaries are valid.
while top <= [1] && left <= right {
The loop continues while the top row index is less than or equal to the bottom row index.
Fill both blanks to correctly traverse the top row from left to right.
for i in [1]..=[2] { result.push(matrix[top][i]); }
We loop from the left column index to the right column index to traverse the top row.
Fill all three blanks to traverse the right column, bottom row, and left column correctly.
for i in ([1]..=[2]).rev() { result.push(matrix[i][right]); } for i in ([3]..=[2]).rev() { result.push(matrix[bottom][i]); }
Traverse down the right column from top+1 to bottom, then traverse the bottom row from right-1 to left in reverse.
