Can anyone provide the optimised soln for this problem.
in an array say there are elements like A[1, 2, 4, 5, 4, 2, 1, 2]. How to caculate the frequency of each number and also print the no with the highest frequency.
In the HashMap the key should be the number and the count should be the value. Iterate over your array, and check if that arrayelement(key) exists in the map, if not exists put that to map with a value 1, or else retrieve the existing value against that key, add 1 to that and put it back into map against that key.
Please correct me if I am wrong.
Joined: Oct 13, 2005
Ambreen Khanam wrote: . . . Are you talking about this example.
. . .
Yes. You have had some suggestions about how you will have to adapt that example to your own requirements.