Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Counter solution in Clear category for Home Coming by Sim0000
from typing import List
from collections import Counter
def home_coming(souvenirs: List[int], s: int) -> int:
max_count = 0
n = len(souvenirs)
for i in range(n):
d = Counter()
for j in range(i, n):
d[souvenirs[j]] += 1
count = sum(d[x] for x in d if d[x] <= s)
max_count = max(count, max_count)
return max_count
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!")
May 26, 2020
Comments: