Java with Simle Approach | With Comments
\n\n\n\nimport java.util.Arrays;\nclass Solution {\n    public int maximumPopulation(int[][] logs) {\n        int start , end;\n        int[] years = new int[20
![image](https://assets.leetcode.com/users/images/54f7bc8b-b48b-49f1-8f1b-5d3ff6162c78_1631777420.5668962.png)\n\n\n```\nimport java.util.Arrays;\nclass Solution {\n    public int maximumPopulation(int[][] logs) {\n        int start , end;\n        int[] years = new int[2051];\n        \n        for(int i=0;i<logs.length;i++){\n            start = logs[i][0];  //Birth year\n            end = logs[i][1];  //Death year\n            for(int x=start;x<end;x++){  // +1 in each year between Birth and ( Death - 1 ) year\n                years[x]++;\n            }\n        }\n        int max=0;int ans=0;\n        for(int i=1950;i<=2050;i++){  //to find maximum polulation year\n            if(max<years[i]){\n                max = years[i];\n                ans = i;\n        }\n        }\n        return ans;\n    }\n}\n\n\n\n\n```\nAfter optimization\n```\n\n\nimport java.util.Arrays;\nclass Solution {\n    public int maximumPopulation(int[][] logs) {\n        int start , end;\n        int[] years = new int[101];\n        \n        for (int i = 0; i < logs.length; i++) {\n            start = logs[i][0];\n            end = logs[i][1];\n            for (int x = start; x < end; x++) {\n                years[x - 1950]++;\n            }\n        }\n        int max = 0;\n        int ans = 0;\n        for (int i = 1950; i <= 2050; i++) {\n            if (max < years[i - 1950]) {\n                max = years[i - 1950];\n                ans = i;\n            }\n        }\n\n\n        return ans;\n    }\n}\n\n\n\n```\n
[]