def min_window(str1, str2):
# write your code here
index_s1, index_s2 = 0, 0
min_length = float('inf')
min_word = ''
while index_s1 < len(str1):
if str1[index_s1] == str2[index_s2]:
index_s2 += 1
if index_s2 == 1:
start_sub_array = index_s1
if index_s2 == len(str2):
# start,end = index_s1, index_s1 + 1
# index_s2 -= 1
# while index_s2 >= 0:
# if str1[start] == str2[index_s2]:
# index_s2 -= 1
# start -= 1
# start = start + 1
if min_length > index_s1-start_sub_array + 1:
min_word = str1[start_sub_array:index_s1+1]
min_length = index_s1-start_sub_array + 1
print(min_length,min_word)
index_s2 = 0
index_s1 += 1
return min_word
Course: Grokking Coding Interview Patterns in Python - Learn Interactively
Lesson: Minimum Window Subsequence - Grokking Coding Interview Patterns in Python