Last active
December 14, 2017 16:28
-
-
Save crevier/42500535790371fc014a23fa135de771 to your computer and use it in GitHub Desktop.
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
//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