Skip to content

Instantly share code, notes, and snippets.

@jackliusr
Last active August 29, 2015 14:05
Show Gist options
  • Save jackliusr/2bf3fc13c30d2f942fcb to your computer and use it in GitHub Desktop.
Save jackliusr/2bf3fc13c30d2f942fcb to your computer and use it in GitHub Desktop.
Hackerran angry children in scala
object Solution{
def main(args: Array[String]) ={
val lines = io.Source.stdin.getLines.drop(1).toList
val k = lines(0).toInt
val kNumsSets = lines.drop(1).map( l => BigInt(l)).sorted.toArray
var unfairness = kNumsSets.last
for(i <- 0 to kNumsSets.size -k -1){
val diff= kNumsSets(i + k-1 ) - kNumsSets(i)
if( diff < unfairness) unfairness = diff
}
println(unfairness)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment