C++ || 0 ms || Line Sweep Algorithm
Code\n\nclass Solution {\npublic:\n    int maximumPopulation(vector<vector<int>>& logs) \n    {\n        // make a population array to store the number of peopl
# Code\n```\nclass Solution {\npublic:\n    int maximumPopulation(vector<vector<int>>& logs) \n    {\n        // make a population array to store the number of people alive in the given year\n        vector<int> population(101, 0);\n        int sum = 0;\n        int maxi = INT_MIN;\n        int ans;\n\n        for(int i=0; i<logs.size(); i++)\n        {\n            // adding 1 to the birth year of the person\n            population[logs[i][0] - 1950] += 1;\n            // subtracting 1 from the death year of the person\n            population[logs[i][1] - 1950] -= 1;\n        }\n\n        // same as the prefix sum\n        // if a person was born in a specific year then he will be counted in the population till the year he dies.\n        for(int i=0; i<population.size(); i++)\n        {\n            sum += population[i];\n            \n            if(sum > maxi)\n            {\n                maxi = sum;\n                ans = i + 1950;\n            }\n        }\n\n        return ans;\n    }\n};\n```
['Line Sweep', 'C++']