Skip to content

Instantly share code, notes, and snippets.

@fancellu
Last active August 29, 2015 14:17
Show Gist options
  • Save fancellu/07fbd9b78f10ec2e4212 to your computer and use it in GitHub Desktop.
Save fancellu/07fbd9b78f10ec2e4212 to your computer and use it in GitHub Desktop.
Quick coding test. Given tasks to people, find person with most tasks, that finished first
// Broken apart to ease understanding.
val s1=Seq(1,1,1,2,2,2,3,3,3,3,4,4,4,4,1)
val groups=s1.groupBy { identity }
val sizes=groups.mapValues { _.size}
val maxSize=sizes.values.max
val maxUsers=sizes.filter(_._2==maxSize).keys.toSet
val pop=s1.filter(maxUsers).zipWithIndex
val lastPlaces=pop.groupBy(_._1).mapValues(_.last)
val quickest=lastPlaces.values.minBy(_._2)._1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment