I read somewhere that using collections.Counter is faster for getting the count of the elements in an array. Is this true?
If yes, can someone tell me why did 233131667 TLE while 233285899 using inbuild python dictionary get Accepted? I tried using collections.defaultdict which also gave TLE.
Apologies if I am missing something.








Python dictionaries are really frail, and if you know how they work, you can easily construct input data that makes them take O(n^2) time. The reason there was a difference between your submissions is because your code is different between the two submission. In the one that survived, you set
cnt[1]=0, which broke the hack in test case 27 (since it relies on key=1 not being in the dictionary until the very end).Here is an anti-hash hack generator for Python dictionaries (it supports CPython dicts, and PyPy dicts and sets)
To generate a hack for both of your submissions, I had to make $$$x \ge 3$$$ since you have
cnt[1] = 0andcnt[2] = 0in your code.Makes me realize how much I have left to learn. Thanks a lot :)