forked from TECHOUS/DSKaKhel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindMaxOddCount.cpp
More file actions
39 lines (31 loc) · 831 Bytes
/
findMaxOddCount.cpp
File metadata and controls
39 lines (31 loc) · 831 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
#include<iostream>
#include<limits>
#include<map>
#include<iterator>
using namespace std;
long int findMaxOdd(long int *,long int);
int main(){
long int size;
cin>>size;
long int * arr = new long int[size];
for(long int i = 0 ; i < size ; i++){
cin>>arr[i];
}
long int result = findMaxOdd(arr,size);
cout<<"The result is "<<result<<endl;
}
long int findMaxOdd(long int *arr,long int size){
map <long int,long int> store;
map <long int,long int> :: iterator it;
long int maximum = INT_MIN;
for(long int i = 0 ; i < size ; i++){
if(arr[i] % 2 != 0){
store[arr[i]]++;
}
}
for(it = store.begin() ; it != store.end() ; it++){
maximum = max(it->second,maximum);
}
it = store.find(maximum);
return it->first;
}