Skip to content

Instantly share code, notes, and snippets.

@leoromanovsky
Created February 19, 2018 21:44
Show Gist options
  • Save leoromanovsky/41de75d66497a61eeef35b1e4072e2cc to your computer and use it in GitHub Desktop.
Save leoromanovsky/41de75d66497a61eeef35b1e4072e2cc to your computer and use it in GitHub Desktop.
persons.flatMap(p => Seq((p.birthYear, 1), (p.deathYear, -1)))
.sorted
.foldLeft((0,0,0)){case ((mxYear,mxPop,curPop), (thisYear,dif)) =>
if (curPop+dif > mxPop) (thisYear, curPop+dif, curPop+dif)
else (mxYear, mxPop, curPop+dif)
}._1 //res0: Int = 2000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment