substring:
you are given two strings N &K your goal is to determine the smallest substring of N that contains all the characters in K If no substring present in N print No matches found
note: if a character is repeated multiple time in K your substring should also contain that character repeated the same no.of times
i/p:the 1st line input two strings N&K
input:
stealen lent
o/p:
tealen
i/p:
tomato tomatho
no matches found
def find_smallest_str( s1, s2):
for i in range(1,len(s1)+1):
for j in range(len(s1)-i+1):
all_in = True
for char in s2:
if char not in s1[j:j+i]:
all_in = False
break
if all_in:
print(s1[j:j+i])
return
print('no matches found')
s1, s2 = input().split()
find_smallest_str( s1, s2)
Comments
Leave a comment