Find the most frequent two elements in a array?
Anonymous
Using hashmap to loop the array once. Then get the number of each element. Then use proirityqueue to loop the hashmap. If the size of the priorityqueue is larger than 2, poll the queue. When the hashmap is looped once. The two elements in the queue are the two most frequent.
Check out your Company Bowl for anonymous work chats.