Minimum Distance Between Words of a String. Given a string s and two words w1 and w2 that are present in S. The task is to find the minimum distance between w1…