Complete the code to initialize the starting row index for spiral traversal.
int top = [1];The top row index starts at 0 because matrix indexing begins at 0.
Complete the code to move the left boundary right after traversing the top row.
left [1] 1;
We increase the left boundary by 1 to move it right after traversing the top row.
Fix the error in the loop condition to traverse the bottom row from right to left.
for (int i = right; i [1] left; i--) { result.push_back(matrix[bottom][i]); }
The loop must continue while i is greater than or equal to left to include the left boundary element.
Fill both blanks to update the top and bottom boundaries after traversing rows.
top [1] 1; bottom [2] 1;
After traversing the top row, we move top down by adding 1. After traversing the bottom row, we move bottom up by subtracting 1.
Fill all three blanks to complete the while loop condition for spiral traversal.
while (top [1] bottom && left [2] right) { // traversal code left [3] 1; }
The loop continues while top is less than or equal to bottom and left is less than or equal to right. We increment left boundary inside the loop.
