Can anybody help me with the code of finding the mode of some datas? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can anybody help me with the code of finding the mode of some datas?

6th Aug 2019, 4:35 AM
AmirAli
AmirAli - avatar
4 Answers
+ 5
Share your try first
6th Aug 2019, 5:14 AM
Muaz Ahmad
Muaz Ahmad - avatar
+ 1
Thanks
6th Aug 2019, 5:30 PM
AmirAli
AmirAli - avatar
0
I don't have any idea of how to write that code😔
6th Aug 2019, 5:19 AM
AmirAli
AmirAli - avatar
0
Ok let's design your program together. If I understand correctly, you have a series of numbers, and you want to find the most common number that appears the most times in the series. (this is 'mode'). So one simple algorithm could be this. 1. Your numbers are in an array or list 2. you create an empty HashMap 3. Iterate over the array and populate the hashmap in a way that the numbers are keys, and every time you iterate a number you increase the associated value in hashmap 4. Finally iterate through the hashmap to find the item with the largest value - that key is your solution
6th Aug 2019, 6:15 AM
Tibor Santa
Tibor Santa - avatar