# LeetCode: Maximum Population Year Solution

```.css-ds3kc{display:table-row;}.css-1t8atru{display:table-cell;opacity:0.5;padding-right:var(--chakra-space-6);-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;text-align:right;}1.css-2qghsv{display:table-cell;}/**2 * @param {number[][]} logs3 * @return {number}4 */5var maximumPopulation = function (logs) {6  let yearPop = new Map()7  logs.forEach(([birth]) => yearPop.set(birth, 0))8
9  for (const [year] of yearPop) {10    for (const [birth, death] of logs) {11      if (birth <= year && year < death) {12        yearPop.set(year, yearPop.get(year) + 1)13      }14    }15  }16
17  const maxPop = Math.max.apply(null, [...yearPop.values()])18  const yearsWithMaxPop = [...yearPop.entries()]19    .filter(([_, pop]) => pop === maxPop)20    .map(([year, _]) => year)21
22  return Math.min.apply(null, yearsWithMaxPop)23}```

leetcode

array

hash table

## Next Post

LeetCode: Maximum Distance Between A Pair Of Values

May 9, 2021

Search Posts