Skip to content

Instantly share code, notes, and snippets.

@prat0318
Created November 10, 2013 03:26
Show Gist options
  • Save prat0318/7393329 to your computer and use it in GitHub Desktop.
Save prat0318/7393329 to your computer and use it in GitHub Desktop.
lowest substring of a containing all characters of string b
def sublength(a, b):
hash_b = {}
for char in set(b):
hash_b[char] = -1
min_length = len(a)+1
for i, char in enumerate(a):
if char in hash_b:
hash_b[char] = i
if (min(hash_b.values()) != -1) & (i - min(hash_b.values()) + 1 < min_length) :
print hash_b
min_length = i - min(hash_b.values()) + 1
if min_length != len(a) + 1:
return min_length
else:
return 0
print sublength("asdfgdghgo","sdfh")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment