JAVA | Line Sweep | 100% | Prefix Sum
IntuitionWe will maintain entire timeline of years(1950-2050) in an array.
Line Sweep: It involves sweeping a line (or point) across a plane or sequence, proces
# Intuition
We will maintain entire timeline of years(1950-2050) in an array.
 Line Sweep: It involves sweeping a line (or point) across a plane or sequence, processing events as they are encountered.
# Approach
Instead of finding total population of each year, we will find number of births and deaths for a year. 
Then to find population for each year we will just use prefix sum to find cumulative sum at that year.

# Complexity
- Time complexity: O(N)
 ->Iterating over all intervals of logs array: O(N)
->Iterating over the 101 years in pop: O(101)=O(1) constant because the range is fixed.
->Overall: O(n+101)=O(n)

- Space complexity: O(1)
->Fixed size of 101: O(101)=O(1)


# Code
```java []
class Solution {
    public int maximumPopulation(int[][] logs) {
        int pop[]=new int[101];
        for(int i=0;i<logs.length;i++){
            pop[logs[i][0]-1950]++;
            pop[logs[i][1]-1950]--;
        }
        int maxPop=pop[0];
        int maxYear=1950;
        for(int i=1;i<101;i++){
            pop[i]+=pop[i-1];
            if(pop[i]>maxPop){
                maxPop=pop[i];
                maxYear=i+1950;
            }
        }
    return maxYear;
    }
}
```
['Prefix Sum', 'Java']