How to find smallest substring which contains all characters from a given string?

To see more details including working code, check my blog post at: http://www.leetcode.com/2010/11/finding-minimum-window-in-s-which.html To help illustrate this approach, I use an example: string1 = “acbbaca” and string2 = “aba”. Here, we also use the term “window”, which means a contiguous block of characters from string1 (could be interchanged with the term substring). i) string1 = …

Read more

How To Get All The Contiguous Substrings Of A String In Python?

The only improvement I could think of is, to use list comprehension like this def get_all_substrings(input_string): length = len(input_string) return [input_string[i:j+1] for i in xrange(length) for j in xrange(i,length)] print get_all_substrings(‘abcde’) The timing comparison between, yours and mine def get_all_substrings(string): length = len(string) alist = [] for i in xrange(length): for j in xrange(i,length): alist.append(string[i:j …

Read more