Here is my attempt : FIMwbF - Online C++ Compiler & Debugging Tool - Ideone.com which is giving wrong answer, it happens to answer all the test cases and I proceed in such a way that it always gives the minimum value with the maximum count. Are there any other corner cases where it fails ? I can’t happen to find one.
Thanks
EDIT : Now I’m trying to get 0.00 execution time,managed 0.08 so far.
Just change the size of array from 10000 to 10010 for safe side and you’ll get AC’ed. Reason as you are incrementing the count at index of number so if number is 10000 then your code will fail as last index of your array will be 9999
Again using single hash approach while taking input i stored value in hash and at the same time i counted the max value in hash but this time i checked that
if hash(inputValue)==currMaxValue :
if inputValue < answer:
then currMaxValue =hash(inputValue)
answer=inputValue
and after iteration i printed answer and currMaxValue.
The problem is solved, another possible question I have in mind is that is there any way of reducing the time complexity further using the same approach ?
@h1ashdr@gon Please try mentioning doubts/problems to someone’s answer as a comment, not as a separate answer. It’s a good practise and even keeps your question’s forum organised.
I think we can, I used two hashes. One for counting the occurrences and other I hashed the count values. That is stored the element for its corresponding count. Something like this: kZMnhq - Online C++ Compiler & Debugging Tool - Ideone.com. Simultaneously, I inserted the count in a set and found the maximum count. This becomes logarithmic in time complexity. And then I output the number for which I have that count. But it’s giving TLE.
@damn_me ,
I managed to get AC (your solution) with faster I/O. http://www.codechef.com/viewsolution/5632824
but its 5 seconds!! its almost 5 times as bad.
I don’t think its a good idea to use 2 hashes somehow.
After several optimizations,my execution time is reducing by 0.02
I am on 0.08 now.I guess to get 0.00 I need to remove the for loop! That would change the whole method but.