Difference Array | Space Optimization with Explanation
 You might have seen many solutions using array of size 2050 for difference array / line sweep.  But we can do better than that.\n\nFrom constraints 1950 <= bir
<br/> You might have seen many solutions using array of size 2050 for difference array / line sweep. <br/> But we can do better than that.\n\nFrom constraints `1950 <= birth[i] < death[i] <= 2050` we can see that number of years will be at max 101 (1950 - 2050). <br/>So we can use an array of size 101 in which `the index i will represent the year i + 1950`\n<br/> Then we can follow the typical Difference array approach\n\n* Initially make population count in all years as 0\n* For each log in logs, **increment count for birth[i] year (log[0]) and decrement count for death[i] year (log[1])**\n* Calculate prefix sum of the array and you will get the population count in each year\n* Keep track of the index i which has maximum population\n* **Return i + 1950** (The year with maximum population)\n<br/>\n\n```cpp\nint maximumPopulation(vector<vector<int>>& logs) {\n        \n        vector<int> years(101, 0);\n        \n        for(auto &log: logs) {\n            years[log[0] - 1950]++;\n            years[log[1] - 1950]--;\n        }\n        \n        int maxPopulation = years[0];\n        int year = 1950;\n        \n        for(int i = 1; i <= 100; i++) {\n            years[i] += years[i - 1];\n            \n            if(years[i] > maxPopulation) {\n                maxPopulation = years[i];\n                year = i + 1950;\n            }\n        }\n        \n        return year;\n    }\n```\n<br/>
['C', 'C++']