Given n ranges of the form L and R , the task is to find the maximum occurred integer in all the ranges. If more than one such integer exists, print the smallest one.
Task # 1
0 <= L[i] , R[i] < 1000000.
Task # 2
0 <= L[i], R[i] < 1000000000.
Task 1 can be easily done with the below algorithm
- Initialize an array arr to 0.
- For each range i, add +1 at Li index and -1 at Ri of the array.
- Find the prefix sum of the array and find the smallest index having maximum prefix sum.
For task #2 it is impossible to make an array of 1e9 , so how we do that , Help please.