Skip to content

Latest commit

 

History

History
34 lines (26 loc) · 697 Bytes

Maximum Common integer.md

File metadata and controls

34 lines (26 loc) · 697 Bytes
int maxOccured(int n, int l[], int r[], int maxx) {

        // Your code here
        vector<int> v(maxx + 2, 0);
        
        for(int i=0;i<n;i++)
        {
            v[l[i]]++;
            v[r[i]+1]--;
        }
        
        int ans = -1;
        int maxi=-1;
        int prefixSum =0;
        int i=0;
        
        for(i;i<v.size();i++)
        {
            prefixSum +=v[i];
            
            if(prefixSum>maxi)
            {
                maxi = prefixSum;
                ans =i;
            }
        }
        
        return ans;
    }