Explanations The function accepts two arguments: a word list and the string s. First, it determines if s or words are empty and returns -1 if either is. Then, a…