input: Write a function to optimize the given Python code for sorting a list of integers in linear time. The given code currently sorts the list by repeatedly finding and removing the minimum element, which results in an O(n^2) time complexity. The goal is to optimize it to achieve O(n) time complexity.
  assert sort_list([2, 6, 3, 8, 4])==[2, 3, 4, 6, 8]
  assert sort_list([9, 1, 5, 7, 3])==[1, 3, 5, 7, 9]
  assert sort_list([10, 20, 30, 40, 50])==[10, 20, 30, 40, 50]
  assert sort_list([1])==[1]
  assert sort_list([])==[]
output: def sort_list(lst):
      if not lst:
          return []
      min_val = min(lst)
      max_val = max(lst)
      count = [0] * (max_val - min_val + 1)
      for num in lst:
          count[num - min_val] += 1
      sorted_lst = []
      for i in range(len(count)):
          sorted_lst.extend([i + min_val] * count[i])
      return sorted_lst