What is wrong in this it is solution of multiple of 3 question of dsa learning series

cook your dish here

t=int(input())
for i in range(t):
sum=0
k,d0,d1=map(int, input().split())
l1=[d0,d1]
for i in range(2,k):
l1.append(0)
for j in range(0,i):
l1[i]+=l1[j]
l1[i]=l1[i]%10
for p in range(len(l1)):
sum+=l1[p]
if(sum%3==0):
print(“YES”)
else:
print(“NO”)

Look at constraints 2 ≤ k ≤ (10^12).So your code just fails!

1 Like

can you please give me hint what should i do if some test case has large inputs , actually it had done twice that my code does not work for large inputs

try to develop a logic in the number making which can reduce for while loop

I found that 8624 repeats but I m not able to relate

Problem is not with large inputs.But actually complexity.Here ur code will perform roughly 10^12 operations.But the max is 10^8.So you just have to come up with more optimal solution.

3 Likes