Complete the code to initialize the starting row index for spiral traversal.
top = [1]The top row index starts at 0 because matrix indexing begins from 0.
Complete the code to move the left boundary right after traversing the left column.
left [1]= 1
After traversing the left column, we move the left boundary right by increasing it by 1.
Fix the error in the loop condition to continue spiral traversal while boundaries are valid.
while top [1] bottom and left <= right:
The loop should continue while the top boundary is less than or equal to the bottom boundary to cover all rows.
Fill both blanks to correctly traverse the top row from left to right.
for i in range([1], [2] + 1): result.append(matrix[top][i])
We traverse the top row from the left boundary to the right boundary inclusive.
Fill all three blanks to traverse the right column from top+1 to bottom and then update the right boundary.
for i in range([1] + 1, [2] + 1): result.append(matrix[i][[3]]) right -= 1
Traverse from the row below top to bottom along the right column, then move the right boundary left.