How can these 2 similiar solutions give different things ..One AC and other WA ?

The first solution is http://www.codechef.com/viewsolution/6374397

The second solution is http://www.codechef.com/viewsolution/6374505

The reason is that in the code that gives WA you have declared the dictionary outside the loop which goes from 1 to t. Due to this the entries of the previous test case still remain in the dictionary. You need to clear the dictionary after each test case…or you could reinitialize it as you have done in the code that is ACed. Hope this helps…:slight_smile:

Oh !! I didn’t noticed it … Isn’t there any way to clear the dictionary after each test case

Sorry for the late reply…i think there is a “clear” method for that…it can be used as “d.clear()”…hope this helps…:slight_smile:

1 Like

Thanks a lot @kunal361