Created
June 16, 2018 06:33
-
-
Save mikekwright/05f112c3ce8ff7dfd8e9e3d64d92f5e1 to your computer and use it in GitHub Desktop.
Codingame Scala solution for Horse Racing Duals (https://www.codingame.com/training/easy/horse-racing-duals)
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
| import math._ | |
| import scala.util._ | |
| /** | |
| * Auto-generated code below aims at helping you parse | |
| * the standard input according to the problem statement. | |
| **/ | |
| object Solution extends App { | |
| val n = readInt | |
| val strengths = (1 to n).map(_ => readInt).sortWith(_ < _) | |
| val diffs = strengths.sliding(2).map(l => Math.abs(l(0) - l(1))) | |
| println(diffs.reduceLeft(_ min _)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment