Created
November 10, 2013 03:26
-
-
Save prat0318/7393329 to your computer and use it in GitHub Desktop.
lowest substring of a containing all characters of string b
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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