input: Write a function to generate a Markov chain given a text input. The function should split the text into words, build a dictionary representing the Markov chain where each word maps to a dictionary of following words and their frequencies, then generate a new text using this chain. If the text input is empty, the function should return an empty string.
  assert generateMarkov("Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, `and what is the use of a book,' thought Alice `without pictures or conversation?'") == "Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, `and what is the use of a book,' thought Alice `without pictures or conversation?"
  assert generateMarkov("") == ""
  assert generateMarkov("the quick brown fox jumps over the lazy dog") == "the quick brown fox jumps over the lazy dog"
  assert generateMarkov("a a a") == "a a a"
  assert generateMarkov("hello") == "hello"
  assert generateMarkov("a b c d e") == "a b c d e"
output: def generateMarkov(text):
      if not text:
          return ""
      
      words = text.split()
      chain = {}
      
      for i in range(len(words) - 1):
          current_word = words[i]
          next_word = words[i + 1]
          
          if current_word not in chain:
              chain[current_word] = {}
          
          if next_word not in chain[current_word]:
              chain[current_word][next_word] = 0
          
          chain[current_word][next_word] += 1
      
      result = []
      current_word = words[0]
      
      for _ in range(len(words)):
          result.append(current_word)
          if current_word in chain:
              next_word = max(chain[current_word], key=chain[current_word].get)
              current_word = next_word
          else:
              break
      
      return ' '.join(result)