I am facing time limit error in one test case.
Kindly have a look at the code.
Mike And HashTrick
@mananaroramail
Their is a better approach nLog(n).
We know every time 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.
I have slightly modified your code : https://ide.codingblocks.com/s/172289
The linked List has a node which has both key and value.
And you are trying to sort the list so formed on the basis of the value of each node.
Collections.sort(list, new Comparator<Map.Entry<Integer, Integer>>() {
public int compare(Map.Entry<Integer, Integer> o1, Map.Entry<Integer, Integer> o2) {
return (o1.getValue()).compareTo(o2.getValue());
}
});
I didn’t understand this part of the code.
@mananaroramail,
Very sorry for the late reply. I have basically created a Comparator to sort the list. The code you mentioned is a comparator
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.
I just wanted to know how can I learn the application of " COLLECTIONS " in java as I am encountering this concept several times. I have searched how sorting and conversions takes place and they are mostly based on Collections.