Given an array of unique characters
arrand a string
str, implement a function
getShortestUniqueSubstringthat finds the smallest substring of
strcontaining all the characters in
""(empty string) if such a substring doesn’t exist.
This algorithm is used.
import collections import sys def get_shortest_unique_substring(substring, string): def trim_left(substring, window, count): ''' find how much left pointer can be moved in a window where all substring is present''' for left, c in enumerate(window): if c in count and count[c] > 1: count[c] -= 1 elif c not in count: continue else: return left return 0 substring = set(substring) ''' validating input ''' if not substring or not string: return "" if len(substring) == len(string) and substring == set(string): return string window, min_window, min_window_len = , , sys.maxint left, right, count = 0, 0, collections.Counter() # to check if the initial minimum window has been found which has all the substring substr_found = set(substring) for right, c in enumerate(string): if c in substring: count[c] += 1 if c in substr_found: substr_found.remove(c) # window has been found and now trim left pointer as much as possible maintaining the invariant that substr is still present between left and right pointers if not substr_found: left += trim_left(substring, string[left:right+1], count) # update the minimum window if right - left + 1 < min_window_len: min_window_len, min_window = right - left + 1, string[left:right+1] # we can't find better window than the length of substr if len(min_window) == len(substring): return "".join(min_window) return "".join(min_window)
✓ Extra quality
ExtraProxies brings the best proxy quality for you with our private and reliable proxies
✓ Extra anonymity
Top level of anonymity and 100% safe proxies – this is what you get with every proxy package
✓ Extra speed
1,ooo mb/s proxy servers speed – we are way better than others – just enjoy our proxies!
USA proxy location
We offer premium quality USA private proxies – the most essential proxies you can ever want from USA
Our proxies have TOP level of anonymity + Elite quality, so you are always safe and secure with your proxies
Use your proxies as much as you want – we have no limits for data transfer and bandwidth, unlimited usage!
Superb fast proxy servers with 1,000 mb/s speed – sit back and enjoy your lightning fast private proxies!
99,9% servers uptime
Alive and working proxies all the time – we are taking care of our servers so you can use them without any problems
No usage restrictions
You have freedom to use your proxies with every software, browser or website you want without restrictions
Perfect for SEO
We are 100% friendly with all SEO tasks as well as internet marketing – feel the power with our proxies
Buy more proxies and get better price – we offer various proxy packages with great deals and discounts
We are working 24/7 to bring the best proxy experience for you – we are glad to help and assist you!