Mike and HashTrick

Here’s the link to my code


The output of the above code is the Wrong Answer.
I don’t know what I am doing wrong.

hi mohd
you are using map to store numbers and their hash values respectively. But many numbers can correspond to same hash value and thus can create problem.
I think In the question also they have assumed that all numbers map to different hash values. But this must be corrected.

I don’t understand what you are trying to say. I watched the hint video and coded my problem according to that.
Can you show in the code as to what I am doing wrong?
Here’s a link to the different code which is according to the hint video present in the course


Give an example apart from the sample input given in the question.

I actually don’t have the lecture video available, according to question output format :
Print k lines, where k is the number of distinct integers in A. ith line contains integer whose hash value is (i-1)., when we run on your code on input like:
4
1 2 1 3
output:
2
1
3
as hashvalue of 2=0, 1=1, 3=2, so we display according to increasing hashvalues.

if i run on input
10
1 2 1 3 1 1 1 2 2 3
output:
hashvalue of 1=0, 2=0, 3=2
how do we display such an output??
This is the problem i am talking about.

Alright. I understand your point. But how should I solve it ? You can discuss this problem with someone who has solved it and then let me know.

Sure, I have raised the question to mentor attention.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.