input: Write a python function to print a 2D array in spiral order.
  assert spiralPrint(3, 3, [[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == "1 2 3 6 9 8 7 4 5"
  assert spiralPrint(4, 4, [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]) == "1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10"
  assert spiralPrint(2, 2, [[1, 2], [3, 4]]) == "1 2 4 3"
output: def spiralPrint(m, n, arr):
      result = []
      top, left = 0, 0
      bottom, right = m - 1, n - 1
  
      while top <= bottom and left <= right:
          for i in range(left, right + 1):
              result.append(arr[top][i])
          top += 1
  
          for i in range(top, bottom + 1):
              result.append(arr[i][right])
          right -= 1
  
          if top <= bottom:
              for i in range(right, left - 1, -1):
                  result.append(arr[bottom][i])
              bottom -= 1
  
          if left <= right:
              for i in range(bottom, top - 1, -1):
                  result.append(arr[i][left])
              left += 1
  
      return " ".join(map(str, result))