-
Notifications
You must be signed in to change notification settings - Fork 4
/
q2.cpp
40 lines (40 loc) · 857 Bytes
/
q2.cpp
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
#include<iostream> //maximum occurrence
using namespace std;
int main()
{
int n,m=0,p=0,l=0;
cout<<"enter size of array:";
cin>>n;
int arr1[n],arr2[n];
cout<<"enter elements of first array:";
for(int i=0;i<n;i++)
{
cin>>arr1[i];
if(arr1[i]>l)
l=arr1[i];
}
cout<<"enter elements of second array:";
for(int i=0;i<n;i++)
{
cin>>arr2[i];
if(arr2[i]>l)
l=arr2[i];
}
int a[l+2]={0},x=0;
for(int i=0;i<n;i++)
{
a[arr1[i]]++;
a[arr2[i]+1]--;
}
for(int i=0;i<=l+1;i++)
{
if(p+a[i]>m)
{
m=p+a[i];
x=i;
}
p=p+a[i];
}
cout<<endl<<"The maximum occurrence is of the element : "<<x;
return 0;
}