Object-Oriented Programming · LinkedIn · Medium
You are to build a data structure called WordDistance that is initialized with a list of words and then answers shortest-distance queries efficiently. The input is a sequence of words referred to as wordsDict. A query asks for two distinct words word1 and word2, and the result is the smallest absolute difference between any index where word1 appears and any index where word2 appears. Both words are guaranteed to exist in wordsDict. Implement the class as follows:…
Checking your access…