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_2 , var_4 = len ( var_0 ) , len ( var_0 [ 0 ] )
      var_6 = [ 0 , 1 , 0 , - 1 ]
      var_7 = [ 1 , 0 , - 1 , 0 ]
      var_8 = [ ]
      var_12 = [ [ False ] * var_4 for var_10 in range ( var_2 ) ]
      var_13 = 0
      var_14 = 0
      var_15 = 0
      for var_10 in range ( var_2 * var_4 ) :
          var_8.append ( var_0 [ var_13 ] [ var_14 ] )
          var_12 [ var_13 ] [ var_14 ] = True
          var_18 , var_19 = var_13 + var_6 [ var_15 ] , var_14 + var_7 [ var_15 ]
          if 0 <= var_18 < var_2 and 0 <= var_19 < var_4 and not var_12 [ var_18 ] [ var_19 ] :
              var_13 , var_14 = var_18 , var_19
          else :
              var_15 = ( var_15 + 1 ) % 4
              var_13 , var_14 = var_13 + var_6 [ var_15 ] , var_14 + var_7 [ var_15 ]
      return var_8
  