Shortest Word Distance

Easy · Hashing · about 10 minutes

Asked at LinkedIn, Snowflake, Google, Amazon, Confluent.

Given an array wordsDict and two different words word1 and word2 that both appear in it, return the shortest distance between an occurrence of word1 and an occurrence of word2.

Related guides