Simple LOGIC : Brute Force : Easy To Understand
Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem at hand is to find the year with the maximum population based on a given se
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem at hand is to find the year with the maximum population based on a given set of birth and death logs. The solution approaches this by simulating the population growth and decline over the years.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1.Initialization:\nint[] population = new int[101];: Initializes an array called population with 101 elements to represent the population count for each year from 1950 to 2050.\n\n2.Population Counting:\n-> for(int i=0; i<logs.length; i++) { ... }: Iterates through each log entry in the logs array.\n-> int x = logs[i][0] - 1950; int y = logs[i][1] - 1950;: Calculates the birth and death years relative to 1950.\n-> for(int a=x; a<y; a++) { population[a]++; }: Increments the population count for each year within the lifespan of an individual.\n\n3.Finding Maximum Population:\n-> int populationCount = 0; int maxYear = 0;: Initializes variables to store the maximum population count and the year with the maximum population.\n-> for(int i=0; i<101; i++) { ... }: Iterates through each year in the population array.\n-> if(population[i] > populationCount) { populationCount = population[i]; maxYear = i + 1950; }: Updates populationCount and maxYear if the population count for the current year is greater than the current maximum.\n\n4.Result:\n->return maxYear;: Returns the year with the maximum population based on the processed logs.\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int maximumPopulation(int[][] logs) {\n        int[] population=new int[101];\n        for(int i=0;i<logs.length;i++){\n                int x=logs[i][0]-1950;\n                int y=logs[i][1]-1950;\n                for(int a=x;a<y;a++){\n                    population[a]++;\n                }\n        }\n        int populationcount=0,maxyear=0;\n        for(int i=0;i<101;i++){\n          if(population[i]>populationcount){\n              populationcount=population[i];\n              maxyear=i+1950;\n          }\n        }\n        return maxyear;\n    }\n}\n\n```
['Java']