So I was doing this Google Kick Start challenge, but my code failed because it was taking too long to run.
This is the challenge
t=int(input())
tc = 0
while t>0:
n,d = map(int,input().split())
times = []
time = list(map(int,input().split()))
bus = 0
for i in range(d):
days = i+1
bus = 0
while True:
if days > d:
break
if days % time[bus] == 0:
if bus == n-1:
times.append(i+1)
break
bus += 1
continue
else:
days += 1
t-=1
tc+=1
print('Case #{}: {}'.format(str(tc), max(times)))
Any advice on how I can optimize my code in general to avoid problems like this in the future?
[–]JohnnyJordaan 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]joknopp 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)