Last active
September 24, 2019 12:27
Star
You must be signed in to star a gist
This file contains 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 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