find the most frequent element in an integer array
Anonymous
Your code is wrong LK: if (max < mp.getValue()) { max = mp.getKey(); } you are comparing max which stores the KEY, with the VALUE of the other keys in the dictionary. Basically if you have 15 appearing once, and 4 appearing 10 times, you are gonna return 15 as value most appeared. Of course you need another variable to keep trace at the same time of the key, and the current max value (number of appearing). Finally, you could do this during the first cycle. The second is not needed.
Check out your Company Bowl for anonymous work chats.