You are given a 2D integer array logs where each logs[i] = [birthi, deathi] indicates the birth and death years of the ith person.

The population of some year x is the number of people alive during that year. The ith person is counted in year x's population if x is in the inclusive range [birthi, deathi - 1]. Note that the person is not counted in the year that they die.

Return the earliest year with the maximum population.

&nbsp;
Example 1:

Input: logs = [[1993,1999],[2000,2010]]
Output: 1993
Explanation: The maximum population is 1, and 1993 is the earliest year with this population.


Example 2:

Input: logs = [[1950,1961],[1960,1971],[1970,1981]]
Output: 1960
Explanation: 
The maximum population is 2, and it had happened in years 1960 and 1970.
The earlier year between them is 1960.

&nbsp;
Constraints:


	1 &lt;= logs.length &lt;= 100
	1950 &lt;= birthi &lt; deathi &lt;= 2050


class Solution:
    def maximumPopulation(self, logs: List[List[int]]) -> int:
        logs.sort(key=lambda x: x[0])
        print(logs)
        living = 0
        max_living = 0
        year = 0

        for ind, (start, stop) in enumerate(logs):
            born = ind+1
            dead = 0
            for i in range(ind):
                if logs[i][1] <= start:
                    dead += 1
            
            living = born - dead
            # print(born, dead, living, max_living)
            if living > max_living:
                max_living = living
                year = start

        
        
        return year
class Solution {
    public int maximumPopulation(int[][] logs) {

        int[] year = new int[2051];

        // O(n) -> n is log.length

        for(int[] log : logs){

            year[log[0]] += 1;
            year[log[1]] -= 1;
        }

        int maxNum = year[1950], maxYear = 1950;

        // O(100) -> 2050 - 1950 = 100

        for(int i = 1951; i < year.length; i++){
            year[i] += year[i - 1]; // Generating Prefix Sum

            if(year[i] > maxNum){
                maxNum = year[i];
                maxYear = i;
            }
        }

        return maxYear;
    }
}
class Solution {
public:
    int maximumPopulation(vector<vector<int>>& logs) {
        int arr[101]={0};
        for(vector<int> log : logs){
            arr[log[0]-1950]++;
            arr[log[1]-1950]--;
        }
        int max=0,year,cnt=0;
        for(int i=0;i<101;i++){
            cnt+=arr[i];
            if(cnt>max)
                max=cnt,year=i;
        }
        return year+1950;
    }
};
var maximumPopulation = function(logs) {
    const count = new Array(101).fill(0);
    
    for (const [birth, death] of logs) {
        count[birth - 1950]++;
        count[death - 1950]--;
    }
    
    let max = 0;
    
    for (let i = 1; i < 101; i++) {
        count[i] += count[i - 1];
        
        if (count[i] > count[max]) max = i;
     }
    
     return 1950 + max;
 };
Maximum Population Year