Advertisement
theinhumaneme

maximum-population-year

Jan 3rd, 2023 (edited)
992
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.72 KB | Source Code | 0 0
  1. // DATE: 03-02-2022
  2. // LINK: https://leetcode.com/problems/maximum-population-year/
  3.  
  4.  
  5. import java.util.*;
  6.  
  7. class Solution {
  8.     public int maximumPopulation(int[][] logs) {
  9.         int[] populationYear = new int[1001];
  10.         for(int[] log: logs){
  11.             for(int i=0; i<=(log[1]-1-log[0]);i++){
  12.                 populationYear[log[0]-1950+i]+=1;
  13.             }
  14.         }
  15.         int max = Arrays.stream(populationYear).max().getAsInt();
  16.         // return max;
  17.         boolean notFound = true;
  18.         int i=0;
  19.         while(notFound){
  20.             if(populationYear[i] == max){
  21.                 notFound = false;
  22.                 break;
  23.             }
  24.             i++;
  25.         }
  26.         return 1950+i;
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement