Skip to content

Instantly share code, notes, and snippets.

@crevier
Last active December 14, 2017 16:28
Show Gist options
  • Save crevier/42500535790371fc014a23fa135de771 to your computer and use it in GitHub Desktop.
Save crevier/42500535790371fc014a23fa135de771 to your computer and use it in GitHub Desktop.
//https://www.hackerrank.com/challenges/hackerland-radio-transmitters/problem
s= new Scanner(System.in);
int n = s.nextInt();
int portee = s.nextInt();
maisons=new TreeSet<>()
for(int x_i=0; x_i < n; x_i++){
maisons.add(s.nextInt())
}
min = maisons.min()
max = maisons.max()
transmiters=[]
for(i = min; i <= max; i++) {
if (maisons.contains(i)) {
k = i + portee
while (!maisons.contains(k)) {
k--
}
transmiters.add(k)
i = k + portee
}
}
println(transmiters.size())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment