C# | O(N Log N) | Sort the census log | Sorting
Intuition: List down all the years on ascending ordering then count the population based on event Birth / Death, when it is death population increases when it i
**Intuition:** List down all the years on ascending ordering then count the population based on event Birth / Death, when it is death population increases when it is death poulation decreases, track the maximum population year. \n\n**Algo:**\n* \tProcess all logs and make it plan list with sorted in year by tracking whether that year is birth (0) or death (1)\n* \tSort the records and calculate population for each year based on the log type.\n* \tTrack the maximum and its year would be our solution\n\n\n**time:**  ```O(n logn)```\n**space:** ```O(n)```\n\n```\npublic class Solution {\n    public int MaximumPopulation(int[][] logs) {\n        int n = logs.Length;\n         \n        List<(int year, int type)> years = new List<(int, int)>();\n        \n        for(int i=0; i<n; i++){\n            years.Add((logs[i][0], 0));\n            years.Add((logs[i][1]-1, 1)); // "logs[i][1] - 1" here reducing 1 as per problem description death year should not be considered living\n        }\n        \n        years = years.OrderBy(x=>x.year)\n                .ThenBy(y=>y.type)\n                .ToList();\n        \n        int maxYear = 0, maxPop =0, pop = 0;\n        foreach(var rec in years){\n            if(rec.type == 0)\n                pop++;\n            else\n                pop--;\n            \n            if(maxPop < pop)\n            {\n                maxPop = pop;\n                maxYear = rec.year;\n            }\n        }\n        return maxYear;\n    }\n}\n```
['Sorting']