Skip to content

Instantly share code, notes, and snippets.

@vchatela
Created February 10, 2016 17:28
Show Gist options
  • Save vchatela/a57efe040f9e72a934ce to your computer and use it in GitHub Desktop.
Save vchatela/a57efe040f9e72a934ce to your computer and use it in GitHub Desktop.
Codingame : Horse-racing Duals Solution
import java.util.*;
import java.io.*;
import java.math.*;
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
**/
class Solution {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int N = in.nextInt();
List<Integer> power = new ArrayList<Integer>();
for (int i = 0; i < N; i++) {
int Pi = in.nextInt();
power.add(Pi);
}
Collections.sort(power);
int answer = Integer.MAX_VALUE;
for (int i = 0; i < power.size()-1; i++) {
int current = power.get(i);
int next = power.get(i+1);
//System.err.println(current + " - " + next);
int D = next - current;
if ( D < answer) {
answer = D;
}
}
System.out.println(answer);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment