Tap here to switch tabs
Problem
Submissions

Problem: Shortest Word Distance

Try to solve the Shortest Word Distance problem.

Statement

Given an array of strings wordsDict and two different strings word1 and word2 that both exist in wordsDict, return the minimum absolute index difference between any occurrence of word1 and any occurrence of word2 in the array.

Constraints:

  • 2≤2 \leq wordsDict.length ≤3imes104\leq 3 imes 10^4

  • 1≤1 \leq wordsDict[i].length ≤10\leq 10

  • wordsDict[i] consists of lowercase English letters.

  • word1 and word2 are in wordsDict.

  • word1 ≠\neq word2

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Shortest Word Distance

Try to solve the Shortest Word Distance problem.

Statement

Given an array of strings wordsDict and two different strings word1 and word2 that both exist in wordsDict, return the minimum absolute index difference between any occurrence of word1 and any occurrence of word2 in the array.

Constraints:

  • 2≤2 \leq wordsDict.length ≤3imes104\leq 3 imes 10^4

  • 1≤1 \leq wordsDict[i].length ≤10\leq 10

  • wordsDict[i] consists of lowercase English letters.

  • word1 and word2 are in wordsDict.

  • word1 ≠\neq word2