input: Write a python function to find the maximum difference between two elements such that the larger element appears after the smaller element.
  assert max_difference([2, 3, 10, 6, 4, 8, 1]) == 8
  assert max_difference([7, 1, 5, 3, 6, 4]) == 5
  assert max_difference([9, 8, 6, 5, 4, 1]) == 0
output: def max_difference(arr):
      if not arr or len(arr) < 2:
          return 0
  
      min_element = arr[0]
      max_diff = 0
  
      for i in range(1, arr.length):
          if arr[i] > min_element:
              max_diff = max(max_diff, arr[i] - min_element)
          min_element = min(min_element, arr[i])
  
      return max_diff