Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Home Coming solution in Speedy category for Home Coming by inkayat
def home_coming(ss, s):
ans = 0
for i in range(len(ss)):
dd = [0 for i in range(1001)]
temp = 0
for j in range(i, len(ss)):
dd[ss[j]]+=1
if dd[ss[j]]==s+1:
temp -= (dd[ss[j]]-1)
elif dd[ss[j]]<=s:
temp+=1
if temp>ans:
ans = temp
return ans
if __name__ == '__main__':
print("Example:")
print(home_coming([1, 1, 4, 1, 4, 4], 2))
print(home_coming([1, 2, 5, 3, 4, 5, 6, 7], 1))
print(home_coming([1, 2, 8, 8, 8, 8, 8, 3, 4, 1], 1))
print(home_coming([13,13,18,13,1,9,18,18,6,17,18,9,7,14,1,20,20,19,3,17,4,17,18,8,20,13,17,12,19,12,16,5,1,17,14,20,8,7,3,15,4,4,14,1,3,7,20,13,20,20,4,4,16,18,11,12,20,15,16,4,5,16,17,20,9,18,10,10,17,6,15,7,14,15,17,9,4,18,19,3,10,10,16,10,2,3,4,15,17,15,2,3,11,6,4,6,2,11,16,3,16,20,1,18,17,1,7,19,6,16,17,8,15,16,1,8,13,2,8,10,11,15,12,12,10,10,16,3,8,4,11,7,6,2,17,9,2,7,1,9,15,17,13,16,19,1,17,8,10,9,9,16,16,13,2,9,20,17,3,13,4,5,20,13,3,7,2,4,20,16,8,17,15,14,4,11,13,13,18,18,15,16,1,6,7,20,20,7,6,14,18,15,11,18,7,4,4,11,18,11,19,6,14,20,17,15,16,10,13,6,2,13,2,14,8,11,6,1,1,17,5,8,1,4,10,17,18,8,8,10,11,18,20,13,11,19,2,6,17,19,19,16,14,16,18,12,7,7,4,10,2,9,6,6,14,6,1,14,17,9,9,11,6,15,20,5,20,1,16,14,3,1,15,7,7,8,3,20,1,1,1,6,4,11,6,6,20,12,7,13,10,18,8,13,7,20,20,12,6,7,1,19,8,9,20,12,7,15,15,12,1,8,19,18,18,7,10,6,16,14,4,8,11,20,1,3,4,5,8,10,2,11,10,15,18,19,14,18,14,9,7,3,12,12,11,18,11,12,10,4,7,5,3,15,2,10,14,18,12,7,17,19,5,10,11,2,2,1,5,3,15,8,19,17,1,16,12,5,11,13,2,3,2,13,5,13,15,2,10,1,11,2,4,20,1,7,4,10,3,11,11,9,6,2,7,10,11,17,12,12,9,11,10,20,1,17,3,16,1,5,13,1,15,1,7,5,18,20,19,20,12,10,11,12,12,10,10,3,12,6,17,13,2,12,19,19,8,14,4,19,5,14,9,5,2,14,7,11,11,6,8,18,2,9,10,7,18,6,1,3,6,18,12,7,11,3,11,16,10,9,17,8,18,2,9,9,20,18,16,4,12,7,9,12,8,9,11,13,5,16,19,4,17,19,18,7,5,15,4,18,9,17,1,2,17,7,1,13,7,7,18,13,16,20,16,8,11,20,1,9,3,18,15,15,8,11,1,6,10,12,8,19,9,18,6,20,18,18,17,1,11,3,10,7,3,13,5,12,19,4,18,1,7,20,10,11,2,19,7,1,2,11,10,11,19,18,2,11,16,16,19,9,6,2,8,6,8,16,17,17,16,3,10,2,18,17,8,3,5,9,15,6,17,17,15,7,20,12,12,6,12,7,16,7,10,18,6,14,13,5,15,18,15,10,14,14,15,11,3,1,3,20,20,12,9,3,16,3,15,10,18,12,14,10,19,17,16,15,14,17,1,10,17,20,16,17,14,2,2,2,2,12,19,9,13,7,19,11,13,10,10,7,16,10,3,19,10,20,8,11,1,3,11,15,17,20,5,10,12,18,20,8,3,7,8,9,1,12,9,12,9,17,14,13,20,7,6,2,3,4,11,7,5,16,3,15,9,18,1,5,2,6,18,2,3,4,2,5,20,11,14,2,12,12,15,9,2,19,13,5,5,9,20,5,14,19,13,3,6,9,13,17,8,10,20,18,13,18,10,1,14,19,10,12,11,6,1,17,1,18,7,19,18,3,10,18,1,16,14,20,4,13,20,18,11,9,17,7,6,20,2,3,17,13,7,8,7,2,13,2,14,6,3,19,1,7,15,9,6,19,10,15,3,6,11,10,16,8,15,17,10,5,4,15,2,12,16,9,7,12,3,8,8,14,18,13,19,9,13,2,1,15,3,12,9,6,16,19,2,20,17,5,18,12,3,18,16,11,2,13,16,9,10,14,3,6,14,17,12,3,12,2,15,16,6,2,3,1,7,15,2,12,3,15,2,5,3,1,10,6,12,9,7,16,19,11,20,15,10,11,15,18,1,18,11,1,18,15,16,9,20,14,10,16,10,11,18,18,2,17,5,12,20,14,13,7,17,11,4,7,3,3,2,18,19,11,9,9,3,10,12,11,1,4,2,18,7,18,17,10,20,9,19,18,18,17,12,18,9,16,17,16,1,9,17,6,20,19,11,10,14,16,6,6,1,7,16,5,6,2,15,6,17,3,19,6,2,2,1,3,15,15,9,18,8,10,1,17,17,19],56))
May 15, 2020
Comments: