You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<!-- Describe your first thoughts on how to solve this problem. -->
7
-
- To traverse all the cells in a grid of size `rows * cols` starting from a specific position (`rStart`, `cStart`) in a spiral order, we can use an array of directions and a variable to keep track of the number of steps needed in each direction.
7
+
- To traverse all the cells in a grid of size `rows * cols` starting from a specific position (`rStart`, `cStart`) in spiral order, we can use an array of directions and a variable to keep track of the number of steps needed in each direction.
8
8
- We will move in sequential directions: **right, down, left, and up**, increasing the number of steps after every two directions (one complete cycle).
- After every two directions, increment the number of steps required.
18
18
19
19
# Complexity
20
-
- Time complexity: **O(n×m)**
20
+
- Time complexity: $O(n \times m)$
21
21
22
22
We will traverse all cells in the grid once, so the time complexity is linear with respect to the number of cells in the grid, or `O(n×m)`, where `n` is the number of rows and `m` is the number of columns.
23
23
24
-
- Space complexity: **O(n×m)**
24
+
- Space complexity: $O(n \times m)$
25
25
26
26
The result array `ans` will contain all positions of the grid, so the space complexity is also linear with respect to the number of cells in the grid, or `O(n×m)`.
27
27
@@ -63,3 +63,5 @@ class Solution
63
63
}
64
64
65
65
```
66
+
67
+
If it can help you, please give me an upvote. Thank you so much for reading!
0 commit comments