Mike and hashtrick problem

i am getting only 1 test case correct and in rest test cases i am getting tle and in one test case i am getting wrong answer please tell my mistakes

hello @lovish2552

ur logic is not optimised.In worst case it is performing o(n^2log(n) ) .

refer this->
if u observe the given hash function then u will find that everytime a number repeats, it is given a new hash value, which is equal to the number of distinct numbers occurred till now. So we can just store the last occurrences of all the numbers and assign the values incrementally, in increasing order of the positions of their last occurrences.

concept video->

still getting tle in last case

@lovish2552
use unordered map in place of map and then try

yes now its working thanks a lot

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.