Find the maximum element of the array. Then, perform a second pass through the array to count the number of maximum elements.
Algorithm implementation
Declare an array.
int m[101];Read the input array. Find its maximum element .
scanf("%d", &n);
max = -2000000000;
for (i = 0; i < n; i++)
{
scanf("%d", &m[i]);
if (m[i] > max) max = m[i];
}In the variable , count the number of maximum elements.
cnt = 0;
for (i = 0; i < n; i++)
if (m[i] == max) cnt++;Print the answer.
printf("%d\n", cnt);Python implementation
Read the input data.
n = int(input())
lst = list(map(int, input().split()))Find the maximum element in the list .
mx = max(lst)Store the count of maximum elements in the variable .
res = lst.count(mx)Print the answer.
print(res)