October LunchTime UNofficial Editorials (First two problems) Revised

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.

3 Likes

The logic of your code isn’t clear to me. Can you elaborate??

Agreed

That ought to be the case, but i thought of real life calculators, which never print 0000. Maybe the author’s calculator wasn’t that faulty to print 0000. :smiley:

3 Likes

Thanks for the explanation :slight_smile:
Can you help me debugging my code for 2nd problem please? LINK

Mate, in his solution, that matters not.

Because he used the condition a>0 || b > 0

If one of them is zero, it will be automatically ignored.

for each i erased character at that place…

And checked the string so formed is divisble by 6 or not

check condition in O(1)

condition:

1.check even or not

2.if yes check (sum-a[i])%3 or not

I think it’s just because erase giving Tle

Possible XD. Imagine my reaction when I opened comment section after 20min only to realzie that leading zeroes are giving WA. I was like, “… (xinfinity)XDXD”

2 Likes

hey taran can u share your fb profile link or can you send me req.? Needed to talk to you personally. :slight_smile:

1 Like

Your code can only delete 3,6 and 9 from given number due to line

if(p%3==0)

Further, no need to check sum%3==0

Simply check (sum-d)%3==0 where d is the deleted digit.

@taran_1407 plzz join this group,it gonna helpful for us!!

https://www.facebook.com/groups/1232901383475983/

As far as i know about c++, String s = p itself takes Linear time, making your solution time out.

How Come??

Surely you can ask anything here mate…

Happens Mate…

I see you haven’t participated in lunchtime…

Ask away mate…

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?

I did use two loops but not two nested loops. There’s a difference. Nested loop is loop within a loop, which i haven’t used and you have.

That’s what that make the difference. :slight_smile:

https://www.codechef.com/viewsolution/16001364
Can you help me debugging my code please?

@taran_1407 the very first solution that passed is O(N^2)! Can you please look at his code and please comment that whether the test cases are weak or he has made some optimization ?

link to the code : https://www.codechef.com/viewsolution/15981694

@soham1234 https://www.codechef.com/viewsolution/16001805

just remove the line where you have checked the value of p and AC :slight_smile:

the idea is that when you get the value lesser, in the position nearer to the units place it will lead to better solution than that in the higher digits !

1 Like