Last active
August 29, 2015 14:05
-
-
Save jackliusr/2bf3fc13c30d2f942fcb to your computer and use it in GitHub Desktop.
Hackerran angry children in scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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