+ 5

Hey guys , do anybody knows , how do I figure out frequently occurring word in an array !!

Let's say there's an array , arr [ ] = { summer , winter , summer , monsoon , winter , summer } Here summer occurs three times So the output must be : summer As it occurs the most , and also how to figure the number of times it occurred !! Thanks to anyone who answers !

21st Feb 2021, 2:53 AM
James Lee
James Lee - avatar
2 Answers
+ 1
You can use a hash map for this. Where key is the word whose frequency is to be calculated and value is frequency of that word in the input. Or You can go for brute force way of iterating repetitively on the array to find the frequency of every distinct elements here.
21st Feb 2021, 3:08 AM
Arsenic
Arsenic - avatar
0
Check out this https://code.sololearn.com/cjwSjf0BBh6X/?ref=app In this đŸ‘†đŸ» code checks if there's any repitition. You can simply count it by i=i+1 for each element that repeats. N say print(i)
16th Mar 2021, 6:20 PM
Srishty M
Srishty M - avatar