input: Write a function to optimize an equation by grouping like terms and expressing them in an exponential form. The input is a string representing the equation which is a sum of variables and their coefficients, and the output is a string representing the optimized equation. If the input is empty, the function should return an empty string.
  assert optimize_equation('x + x + y + y + y')== 'x^2 + y^3'
  assert optimize_equation('a + a + b + b + c + c + c')== 'a^2 + b^2 + c^3'
  assert optimize_equation('z + z + z + z + z')== 'z^5'
  assert optimize_equation('')== ''
  assert optimize_equation('p + q + q')== 'p^1 + q^2'
output: def optimize_equation(equation):
      if not equation:
          return ''
      terms = equation.split(' + ')
      term_count = {}
      for term in terms:
          if term in term_count:
              term_count[term] += 1
          else:
              term_count[term] = 1
      optimized_terms = [f"{term}^{count}" if count > 1 else term for term, count in term_count.items()]
      return ' + '.join(optimized_terms)