Snippets Collections
import java.util.*;
import java.io.*;

class GFG 
{ 
    static int maxOcc(int L[], int R[], int n, int maxx)
    {	
	    	int arr[] = new int[1000000];

	    	for(int i = 0; i < n; i++)
	    	{
	    		arr[L[i]]++;

	    		arr[R[i] + 1]-=1; // arr[R[i] + 1]--;
	    	}

	    	int maxm = arr[0], res = 0;

	    	for(int i = 1; i < maxx; i++) // maxx = 1000000
	    	{
	    		arr[i] += arr[i - 1];

	    		if(maxm < arr[i])
	    		{
	    			maxm = arr[i];

	    			res = i;
	    		}
	    	}

	    	return res;
    }
    public static void main(String args[]) 
    { 
       int L[] = {1, 2, 3}, R[] = {3, 5, 7}, n = 3;

      System.out.println(maxOcc(L, R, n)); 
    } 
}
star

Mon Feb 07 2022 15:07:44 GMT+0000 (Coordinated Universal Time) https://www.geeksforgeeks.org/maximum-occurred-integer-n-ranges/

#java #gfg #geeksforgeeks #lecture #arrays #prefixsum #maximumoccuredinteger

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension