Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Home Coming by bravebug
from typing import List
def home_coming(souvenirs: List[int], s: int) -> int:
result = 0
for n in range(len(souvenirs)):
for k in range(len(souvenirs), n + 1, -1):
temp = souvenirs[n:k]
temp = [temp.count(x) for x in set(temp)]
temp = [x for x in temp if x <= s]
temp = sum(temp)
result = temp if temp > result else result
return result
if __name__ == '__main__':
print("Example:")
print(home_coming([1, 1, 4, 1, 4, 4], 2))
# These "asserts" are used for self-checking and not for an auto-testing
assert home_coming([1, 1, 4, 1, 4, 4], 2) == 4, "Example #1"
assert home_coming([1, 2, 5, 3, 4, 5, 6, 7], 1) == 6, "Example #2"
assert home_coming([1, 2, 8, 8, 8, 8, 8, 3, 4, 1], 1) == 4, "Example #3"
print("Coding complete? Click 'Check' to earn cool rewards!")
July 4, 2020
Comments: