input: Write a function to format a two-dimensional array as a table. The function should ensure that the columns are aligned based on the length of the longest element in each column. If the input array is empty, the function should return an empty string.
  assert printTable([[1, 2, 3], [4, 5, 6], [7, 8, 9]])=='1  2  3\n4  5  6\n7  8  9'
  assert printTable([[1, 12, 3], [4, 5, 6000], [7, 80, 9]])=='1   12   3\n4    5  6000\n7   80   9'
  assert printTable([[1], [4], [7]])=='1\n4\n7'
  assert printTable([])==''
  assert printTable([[1, 2, 3], [4, 5, 6]])=='1  2  3\n4  5  6'
  assert printTable([[1, 2, 3]])=='1  2  3'
output: def printTable(arr):
      if not arr:
          return ''
      num_rows = len(arr)
      num_cols = len(arr[0])
      col_widths = [max(len(str(arr[row][col])) for row in range(num_rows)) for col in range(num_cols)]
      result = []
      for row in arr:
          formatted_row = ' '.join(str(item).rjust(col_widths[col_idx]) for col_idx, item in enumerate(row))
          result.append(formatted_row)
      return '\n'.join(result)