+ 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 !
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.
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)