Updating exercises

This commit is contained in:
Carlos
2025-07-14 10:09:13 -04:00
parent 57956bf728
commit 7f1381ae93
25 changed files with 634 additions and 13 deletions

View File

@@ -44,6 +44,7 @@ class Solution:
pos1 = word_indices[word1]
pos2 = word_indices[word2]
# Two-pointer traversal
i, j = 0, 0
min_distance = float("inf")
@@ -52,6 +53,7 @@ class Solution:
index2 = pos2[j]
min_distance = min(min_distance, abs(index1 - index2))
# Move the pointer pointing to the smaller index
if index1 < index2:
i += 1
else:
@@ -59,6 +61,5 @@ class Solution:
return min_distance
# @leet end