comefrom: <garvit244>54_1.py
code: def spiralOrder( matrix):
      if not matrix:
          return []
      
      R, C = len(matrix), len(matrix[0])
      dr = [0, 1, 0, -1]
      dc = [1, 0, -1, 0]
      
      result = []
      seen = [[False]*C for _ in range(R)]
      row = 0
      col = 0
      di = 0
      for _ in range(R*C):
          result.append(matrix[row][col])
          seen[row][col] = True
          rr, cc = row + dr[di], col + dc[di]
          if 0 <= rr < R and 0 <= cc < C and not seen[rr][cc]:
              row, col = rr, cc
          else:
              di = (di+1)%4
              row, col = row + dr[di], col + dc[di]
      
      return result
masked: def sample_funcname ( var_0 ) :
      if not var_0 :
          return [ ]
      var_1 , var_2 = len ( var_0 ) , len ( var_0 [ 0 ] )
      var_3 = [ 0 , 1 , 0 , - 1 ]
      var_4 = [ 1 , 0 , - 1 , 0 ]
      var_5 = [ ]
      var_7 = [ [ False ] * var_2 for var_6 in range ( var_1 ) ]
      var_8 = 0
      var_9 = 0
      var_10 = 0
      for var_6 in range ( var_1 * var_2 ) :
          var_5.append ( var_0 [ var_8 ] [ var_9 ] )
          var_7 [ var_8 ] [ var_9 ] = True
          var_11 , var_12 = var_8 + var_3 [ var_10 ] , var_9 + var_4 [ var_10 ]
          if 0 <= var_11 < var_1 and 0 <= var_12 < var_2 and not var_7 [ var_11 ] [ var_12 ] :
              var_8 , var_9 = var_11 , var_12
          else :
              var_10 = ( var_10 + 1 ) % 4
              var_8 , var_9 = var_8 + var_3 [ var_10 ] , var_9 + var_4 [ var_10 ]
      return var_5
  