@@ -16,31 +16,31 @@ def generate_matrix(self, n: int) -> list[list[int]]:
1616 while row_start <= row_end and col_start <= col_end :
1717 # Step 1: Fill the top row (left → right)
1818 for i in range (col_start , col_end + 1 ):
19- result [row_start ][i ] = value # assign the current value
20- value += 1 # move to next number
19+ result [row_start ][i ] = value # assign the current value
20+ value += 1 # move to next number
2121 row_start += 1 # move top boundary down (row filled)
22-
22+
2323 # Step 2: Fill the rightmost column (top → bottom)
2424 for row in range (row_start , row_end + 1 ):
2525 result [row ][col_end ] = value
2626 value += 1
2727 col_end -= 1 # move right boundary left (column filled)
28-
28+
2929 # Step 3: Fill the bottom row (right → left)
3030 # Only if there are rows remaining to fill
3131 if row_start <= row_end :
3232 for col in range (col_end , col_start - 1 , - 1 ):
3333 result [row_end ][col ] = value
3434 value += 1
3535 row_end -= 1 # move bottom boundary up (row filled)
36-
36+
3737 # Step 4: Fill the leftmost column (bottom → top)
3838 # Only if there are columns remaining to fill
3939 if col_start <= col_end :
4040 for row in range (row_end , row_start - 1 , - 1 ):
4141 result [row ][col_start ] = value
4242 value += 1
43-
43+
4444 col_start += 1
4545
4646 # return the completed spiral matrix
@@ -58,10 +58,10 @@ def generate_matrix(self, n: int) -> list[list[int]]:
5858 print (row )
5959
6060
61- # Output:
62- '''
61+ # Output:
62+ """
6363 [1, 2, 3]
6464 [8, 9, 4]
6565 [7, 6, 5]
6666
67- '''
67+ """
0 commit comments