Suppose we have a list of numbers called nums, we have to find the most frequently present element and get the number of occurrences of that element.
So, if the input is like [1,5,8,5,6,3,2,45,7,5,8,7,1,4,6,8,9,10], then the output will be 3 as the number 5 occurs three times.
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
class Solution: def solve(self, nums): max=0 length=len(nums) for i in range(0,length-1): count=1 for j in range(i+1,length): if(nums[i]==nums[j]): count+=1 if(max<count): max=count return max ob = Solution() nums = [1,5,8,5,6,3,2,45,7,5,8,7,1,4,6,8,9,10] print(ob.solve(nums))