Mike and hashtrick

Hey can you provide O(n) based solution for this problem as discussed in problem hint video as i am not able to get it.

I try to write another approach and passes testcases - as we want to print numbers according to their increasing hashmap value i just count them, sort and print.

actually the solution provided in the vedio is also o(nlogn) , i have’nt encountered any O(n) solution , i will try to think of one
till now you can refer this code closely resembling what have been told in the vedio :-

Thanks. It is quite similar to mine. One thing - is it important in these type of question where we are given with some code we have to use that and produce answer.
As first i use the code provided in question to solve problem but got TLE.

@Rakshitgarg99, from my experience generally what happens with these type of question is you will be given a function snippet and you have to kind of reimplement the function but there is a catch , the problem is the code that will be provided to you will be complex and inefficient , so your major job is to figure out what is the functionality of that function , i.e what is it doing for that you have to run some test cases and implement that functionality in a optimized way , if implementing the same function as it is will work then there is no point to solve this question

1 Like

ok now i get it. Thanks

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.