O(n) Line Sweep
We can mark the start and end of each life as +1 and -1 on the timeline. Then, we go through timeline from 1950 to 2050 and accumulate the current population fo
We can mark the start and end of each life as +1 and -1 on the timeline. Then, we go through timeline from 1950 to 2050 and accumulate the current population for each year.\n\n**C++**\n```cpp\nint maximumPopulation(vector<vector<int>>& logs) {\n    int pop[2051] = {}, res = 0;\n    for (auto &l : logs) {\n        ++pop[l[0]];\n        --pop[l[1]];\n    }\n    for (auto i = 1950; i < 2050; ++i) {\n        pop[i] += pop[i - 1];\n        res = pop[i] > pop[res] ? i : res;\n    }\n    return res;\n}\n```\n**Java**\n```java\npublic int maximumPopulation(int[][] logs) {\n    int pop[] = new int[2051], res = 0;\n    for (var l : logs) {\n        ++pop[l[0]];\n        --pop[l[1]];\n    }\n    for (int i = 1950; i < 2050; ++i) {\n        pop[i] += pop[i - 1];\n        res = pop[i] > pop[res] ? i : res;\n    }\n    return res;\n}\n```
['C', 'Java']