Browser tab content: Problem List 0 Debugging... Run Submit 00:00:00 Description…
- User
Browser tab content: Problem List 0 Debugging... Run Submit 00:00:00 Description Editorial Editorial Solutions Solutions Submissions Submissions Debugger Debugger Code Note Note Testcase Testcase Test Result 245. Shortest Word Distance III Medium Topics Companies
Given an array of strings wordsDict and two strings that already exist in the array word1 and word2, return the shortest distance between the occurrence of these two words in the list.
Note that word1 and word2 may be the same. It is guaranteed that they represent two individual words in the list.
Example 1:
Input: wordsDict = ["practice", "makes", "perfect", "coding", "makes"], word1 = "makes", word2 = "coding" Output: 1
Example 2:
Input: wordsDict = ["practice", "makes", "perfect", "coding", "makes"], word1 = "makes", word2 = "makes" Output: 3
Constraints:
1 <= wordsDict.length <= 105 1 <= wordsDict[i].length <= 10 wordsDict[i] consists of lowercase English letters. word1 and word2 are in wordsDict. Seen this question in a real interview before? 1/5 Yes No Accepted 84.8K Submissions 144.5K Acceptance Rate 58.7% Topics Array String Companies 0 - 6 months LinkedIn 2 6 months ago Palantir Technologies 2 Similar Questions Shortest Word Distance Easy Shortest Word Distance II Medium Discussion (7) Choose a type Preview Comment 💡 Discussion Rules
-
Please don't post any solutions in this discussion.
-
The problem discussion is for asking questions about the problem or for sharing tips - anything except for solutions.
-
If you'd like to share your solution for feedback and ideas, please head to the solutions tab and post it there.
Sort by:Best No comments yet. 1 Copyright ©️ 2024 LeetCode All rights reserved 506 7 2 Online Java Auto 1 2 3 4 5 class Solution { public int shortestWordDistance(String[] wordsDict, String word1, String word2) { } } Restored from local Ln 3, Col 9 You must run your code first
Employees Earning More Than Their Managers - LeetCode
Problem List Tag 171. Excel Sheet Column Number
Easy
- Factorial Trailing Zeroes
Med.
- Binary Search Tree Iterator
Med.
- Dungeon Game
Hard
- Combine Two Tables
Easy
- Second Highest Salary
Med.
- Nth Highest Salary
Med.
- Rank Scores
Med.
-
- Assistant
Sure, let's extract the key details and provide an efficient solution for the problem "Shortest Word Distance III."