For the second question my solution is O(n) but still giving TLE, please look into this:- CodeChef: Practical coding for everyone
hey taran my code is giving wa in 1st subtask. any testcase where it might fail? yKzrA3 - Online C++ Compiler & Debugging Tool - Ideone.com
Thanks Taran! Great job helping out others. Kudos!
Is erase function also linear in Time???
I think you can add something on how to avoid those leading zeroes. I was simple printing the array and wasted A HUGE CHUNK of my time because it was printing leading 0.
And BTW, I feel the problem statement SHOULD specify that leading zeroes arent allowed. I mean, yeah, to many people “5555+5555=0000” would make sense.
hey taran can u share your fb profile link or can you send me req.? Needed to talk to you personally.
t = int(input())
while t>0 :
n = input()
i = len(n)
flag = 0
li = []
while i>0:
copy = int(n[:i-1] + n[i:])
if copy%6 == 0:
li.append(copy)
flag = 1
i -= 1
if flag == 1:
print(str(max(li)).rjust(len(n)-1, "0"))
else:
print("-1")
t = t-1
I don’t know why it was giving TLE although you have also used nested loops and hence O(n^2)… please help me?
My solution is in O(number of digits). I don’t know why it is giving TLE. This is my solution.
It is in Python. My logic is I calculate the number if I remove one digit, and check if it is divisible by 6 and greater than previously held value and replace it. Then append zeroes according to input if the first digit is removed.
e.g:- 3268398 is input,
num will hold the values (268398, 368398, 328398, 326398, 326898, 326838, 326839) in each iteration respectively.
Will check if it is divisible by 6 and greater than previously divisible value.
Thanks in advance.
My code gives wrong ans.Any test case where it may fail?
link:CodeChef: Practical coding for everyone
for the second question ,every test case i checked is satisfied still i am getting a wrong answer please help me out pointing out just 1 test case that this code cannot run ??
https://www.codechef.com/viewsolution/15988759
What is wrong in this code for BUGCAL? PLease help. Everything handled!
Taran, Can you help me debug my code? It seems like I’m missing some corner cases.
Edit: I’m sorry. The link was wrong. This is link to solution. CodeChef: Practical coding for everyone