code: def word_break(sentence, words):
      n, w = len(sentence), len(words)
      if (n == 0) or (w == 0):
          return None
  
      dw = [-1 for i in range(n + 1)]
      dp = [math.inf for i in range(n + 1)]
      dp[0] = 0
      matched_indices = [0]
  
      dic = {}  # save all words in dictionary for faster searching
      max_word = 0  # length of the max word
      for i in range(w):
          dic[words[i]] = i
          max_word = max(max_word, len(words[i]))
  
      for i in range(1, n + 1):
          matched = False
          # start from the back of the matched_indices list (from the bigger numbers)
          for j in range(len(matched_indices) - 1, -1, -1):
              matched_index = matched_indices[j]
              # break this loop if the subsentence created with this matched index is bigger than the biggest word
              if matched_index < i - max_word:
                  break
  
              subsentence = sentence[matched_index:i]
              # save this result if this subsentence exist in the words and number of words that forms sentence is smaller
              if (subsentence in dic) and (
                  dp[matched_index] + 1 < dp[i]
              ):
                  dp[i] = dp[matched_index] + 1
                  dw[i] = dic[subsentence]
                  matched = True
  
          if matched:
              matched_indices.append(i)
  
      # the sentence can't be composed from the given words
      if dp[n] == math.inf:
          return None
  
      # find the words that compose this sentence
      result = ["" for i in range(dp[n])]
      i = n
      j = dp[n] - 1
      while i > 0:
          result[j] = words[dw[i]]
          i -= len(words[dw[i]])
          j -= 1
  
      return result
  
label_desc: Use image node_id 1 for calling a global function with example usage: word_break(sentence, words) and returns: result, None, None