<p>Given an <code>m x n</code> <code>matrix</code>, return <em>all elements of the</em> <code>matrix</code> <em>in spiral order</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/11/13/spiral1.jpg" style="width: 242px; height: 242px;" />
<pre>
<strong>Input:</strong> matrix = [[1,2,3],[4,5,6],[7,8,9]]
<strong>Output:</strong> [1,2,3,6,9,8,7,4,5]
</pre>

<p><strong class="example">Example 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/11/13/spiral.jpg" style="width: 322px; height: 242px;" />
<pre>
<strong>Input:</strong> matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]
<strong>Output:</strong> [1,2,3,4,8,12,11,10,9,5,6,7]
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>m == matrix.length</code></li>
	<li><code>n == matrix[i].length</code></li>
	<li><code>1 &lt;= m, n &lt;= 10</code></li>
	<li><code>-100 &lt;= matrix[i][j] &lt;= 100</code></li>
</ul>

class Solution:
    def spiralOrder(self, matrix: List[List[int]]) -> List[int]:

        x_min = 0
        y_min = 0
        x_max = len(matrix[0])
        y_max = len(matrix)
        output = []

        mov_x = True
        pos = True

        while ((x_min < x_max) or (y_min < y_max)) and len(output) < len(matrix) * len(matrix[0]):
            if mov_x and pos:
                output += matrix[y_min][x_min:x_max]
                mov_x = False
                y_min += 1
            
            elif not mov_x and pos:
                print("Moving down")
                output += [matrix[y][x_max - 1] for y in range(y_min, y_max)]
                mov_x = True
                pos = False
                x_max -= 1
            
            elif mov_x and not pos:
                print("Moving left")
                print(x_min, x_max)
                output += [matrix[y_max - 1][x] for x in range(x_max - 1, x_min - 1, -1)]
                mov_x = False
                pos = False
                y_max -= 1

            elif not mov_x and not pos:
                print("Moving up")

                output += [matrix[y][x_min] for y in range(y_max - 1, y_min - 1, -1)]
                mov_x = True
                pos = True
                x_min += 1

            print(output)
            
                
                
                    

            
        return output
            


        
16600