Year with the most living (given a list of births and deaths)
The optimal algorithm is about O(n) to generate the count changes per year (and optionally get the first and last year), and about O(m) for enumerating them to find the first year with highest count (where m is preferably the number of years from the first to last year). 



var people = [{ birth: 1720, death: 1860 },{ birth: 1720, death: 1860 },{ birth:1803, death: 1809},{ birth: 1730, death: 1810 },{ birth: 1920, death: 1950 },{ birth: 1930, death: 1940 },{ birth: 1940, death: 1990 }, { birth: 1970, death: 2010 }];

var counts = people.reduce((a, v) =&gt; (a[v.birth] = (a[v.birth] | 0) + 1, 
                                      a[v.death] = (a[v.death] | 0) - 1, a), []);

var maxYear = 0, maxCount = 0, count = 0;
counts.forEach((c, y) =&gt; {
  count += c;
  if (maxCount &lt; count) {
    maxCount = count;
    maxYear = y;
  }
});

console.log( maxYear, maxCount );
console.log( { ...counts } );




The above is just a sample, and can be much more efficient with for(;;) loops and starting the second loop from the first year 1720 instead of 0. The count changes can be in either object {} or Array object [] as long as they are enumerated in order from low to high.