input: Write a function to find the minimum distance between two words in a string.
  assert min_distance_words("the quick brown fox jumps over the lazy dog", "quick", "dog") == 7
  assert min_distance_words("the quick brown fox quick jumps over the quick lazy dog", "quick", "quick") == 0
  assert min_distance_words("the quick brown fox jumps over the lazy dog", "fox", "the") == 1
output: def min_distance_words(s: str, word1: str, word2: str) -> int:
      words = s.split()
      min_distance = float('inf')
      last_pos_word1 = last_pos_word2 = -1
  
      for i, word in enumerate(words):
          if word == word1:
              last_pos_word1 = i
              if last_pos_word2 != -1:
                  min_distance = min(min_distance, abs(last_pos_word1 - last_pos_word2))
          if word == word2:
              last_pos_word2 = i
              if last_pos_word1 != -1:
                  min_distance = min(min_distance, abs(last_pos_word2 - last_pos_word1))
  
      return min_distance if min_distance != float('inf') else -1