-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblemnumber05.cpp
More file actions
48 lines (36 loc) · 931 Bytes
/
problemnumber05.cpp
File metadata and controls
48 lines (36 loc) · 931 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include<iostream>
#include<algorithm>
#include<vector>
#include <array>
#include<cmath>
using namespace std;
// function work to find the count of the most frequent item of an array
int most_frequent_item_count(vector<int> collection) {
int cont = 0;
for (int i = 0; i < collection.size(); i++)
{
int countt = 0;
for (int j = 0; j < collection.size(); j++)
{
if (collection[i] == collection[j])
{
countt++;
}
}
if (countt > cont)
{
cont = countt;
}
}
return cont;
}
int main() {
cout << most_frequent_item_count({ 3, -1, -1, -1, 2, 3, -1, 3, -1, 2, 4, 9, 3 });
return 0;
}
/*Complete the function to find the count of the most frequent item of an array. You can assume that input is an array of integers. For an empty array return 0
Example
input array: [3, -1, -1, -1, 2, 3, -1, 3, -1, 2, 4, 9, 3]
ouptut: 5
The most frequent number in the array is -1 and it occurs 5 times.
*/