Mike and hash trick doubt

what is wrong in this code?
only 3 testcases are passing

Hello @yatin,

The error is in the way you are assigning val to m[a[i]]
Either make both m[a[i]]=val++ or m[a[i]]=++v.

In your code, as you are using different (postfix and prefix) ways to assign val.
Thus, it is causing duplicacy of the same val value to different elements of the map.

Hope, this would help.
Give a like if you are satisfied.

1 Like

ok sir thank you :slight_smile:

@yatin Anytime.

Please, mark it as resolved.


check out the link…it can easily be solved using 2 maps…In O(n)…
If use sorting then it will take O(nlog(n)) time complexity