Skip to content

Instantly share code, notes, and snippets.

@ColorfulCodes
Last active September 24, 2019 12:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ColorfulCodes/fe06161fd570a163b39e54b2f79190f8 to your computer and use it in GitHub Desktop.
def minWindow(s,t):
right =0
left =0
smallest = ""
hold = {}
for i in t:
if i not in hold:
hold[i] = 1
else:
hold[i] += 1
while right < len(s) + 1:
#move right until
if s[right:left] == sorted(t) and len(s[right:left]) > smallest:
smallest =s[right:left]
return smallest
hold this algo
from itertools import combinations
def choose_best_sum(max_distance, k, distances):
best = 0
for combination in combinations(distances, k):
distance = sum(combination)
if distance == max_distance:
return distance
if distance < max_distance:
best = max(best, distance)
return best if best > 0 else None
xs = [100, 76, 56, 44, 89, 73, 68, 56, 64, 123, 2333, 144, 50, 132, 123, 34, 89]
choose_best_sum(230, 4, xs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment