O(N) Optimized And Easy To Understand Code
1. O(n) Optimized Code\n#### Approach\nStoring the population of all the year in an array of size 101 from year=1950 to year=2050. Now finding the earliest year
# 1. O(n) Optimized Code\n#### Approach\nStoring the population of all the year in an array of size 101 from year=1950 to year=2050. Now finding the earliest year having the maximum population.\n\n#### Complexity\n- Time complexity: O(n * 101)\n\n- Space complexity: O(101) ~ O(1)\n\n```\nclass Solution {\n    public int maximumPopulation(int[][] logs) {\n        int[] population = new int[101];\n        for(int year=1950;year<=2050;year++){\n            population[year-1950] = countPopulation(logs,year);\n        }\n        int minYear = Integer.MAX_VALUE, maxPopulation = Integer.MIN_VALUE;\n        for(int index=100;index>=0;index--){\n            int population_ = population[index];\n            if(population_>=maxPopulation){\n                minYear = index+1950;\n                maxPopulation = population_;\n            }\n        }\n        return minYear;\n    }\n\n    // Method to find the population in any given year. ...... O(n)\n    private static int countPopulation(int[][] logs, int year){\n        int count = 0;\n        for(int[] person : logs){\n            int birth = person[0], death = person[1];\n            if(birth<=year && year<death) count++;\n        }\n        return count;\n    }\n}\n\n// Time Complexity : O(n*100)\n// Space Complecity : O(101) ~ O(1)\n\n// 1950 - 2050\n```
['Counting Sort', 'Java']