Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Problem1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#Submitting placeholder answer as I do not remember what the exact question was and I have attended and passed all the 15 mock interviews.

class Solution:
def shortestWordDistance(self, wordsDict: List[str], word1: str, word2: str) -> int:
#only 1 var need- prev
res = float('inf')
prev = -1
for i, word in enumerate(wordsDict):
if word in (word1, word2):

if prev != -1 and (wordsDict[prev] != word or word1==word2):
res = min(res, abs(prev - i))
prev = i

return res