Shortest Word Distance II
Medium · Hashing · about 15 minutes
Asked at LinkedIn, Amazon, Google, Microsoft.
Design a structure built once from wordsDict that answers many queries.
WordDistance(wordsDict)stores the words.shortest(word1, word2)returns the shortest distance between the two (different) words, both present.