Skip to content

Commit 47b257f

Browse files
Create Maximum occured integer
1 parent a846ad7 commit 47b257f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Maximum occured integer

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// L and R are input array
2+
// maxx : maximum in R[]
3+
// n: size of array
4+
// arr[] : declared globally with size equal to maximum in L[] and R[]
5+
//Function to find the maximum occurred integer in all ranges.
6+
int maxOccured(int L[], int R[], int n, int maxx){
7+
8+
long long arr[maxx+2]={0};
9+
int j=0;
10+
for(int i=0; i<n ; i++)
11+
{
12+
arr[L[i]]=arr[L[i]]+1;
13+
arr[R[i]+1]=arr[R[i]+1]-1;
14+
}
15+
int cnt=0;
16+
int max1=0;
17+
int ind=0;
18+
for(int i=0; i<maxx+2; i++)
19+
{
20+
cnt+=arr[i];
21+
if(cnt>max1){
22+
max1=cnt;
23+
ind=i;
24+
}

0 commit comments

Comments
 (0)