Java Simple solution with explanation in comments
Please up vote if you like :)\n\nBrute force approach :\nTime Complexity : O(n^2)\nSpace Complexity : O(n)\n\n\nclass Solution {\n    public int maximumPopulati
Please up vote if you like :)\n\nBrute force approach :\nTime Complexity : O(n^2)\nSpace Complexity : O(n)\n\n```\nclass Solution {\n    public int maximumPopulation(int[][] logs) {\n        \n        //constraints 1 <= logs.length <= 100 and 1950 <= birthi < deathi <= 2050\n        //so max years we can  have is 2050 - 1950 = 100\n        //so create an array for storing population in given years\n        int[] arr = new int[101];\n        \n        //first check logs\n        for(int i=0;i<logs.length;i++){\n            //checking only birthi to deathi(excluding)\n            for(int j =logs[i][0];j<logs[i][1];j++){\n                //counting population\n                arr[j-1950]++;\n            }\n        }\n        \n        \n        int maxPopulationYear = 0;\n        int maxPopulation = 0;\n        //now checking in arr \n        for(int i = 0;i<101;i++){\n            //highest and earliest arr[i] will be our maximum population , and i wil be year \n            if(maxPopulation < arr[i]){\n                maxPopulation = arr[i];\n                //max population year + 1950\n                maxPopulationYear = i + 1950;\n            }\n        }\n        return maxPopulationYear;\n    }\n}\n```\n\nUsing running sum of array :\nTime Complexity : O(n)\nSpace Complexity : O(1)\n\n```\nclass Solution {\n    public int maximumPopulation(int[][] logs) {\n        \n        int [] arr = new int[101];\n        \n        for(int i=0;i<logs.length;i++){\n            arr[logs[i][0] - 1950]++;\n            arr[logs[i][1] - 1950]--;\n        }\n        \n        for(int i = 1;i<101;i++){\n            arr[i] += arr[i-1];\n        }\n        \n        int maxPopulation = 0;\n        int year = 0;\n        for(int i = 0;i<101;i++){\n            if(arr[i] > maxPopulation){\n                maxPopulation = arr[i];\n                year = i + 1950;\n            }\n        }\n        return year;\n    }\n}\n```\n
['Java']