Created
February 2, 2016 14:59
-
-
Save oddlyfunctional/ca721e3c587e45f21979 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
#!/bin/ruby | |
# https://www.hackerrank.com/contests/worldcodesprint/challenges/powerplants-in-flatland | |
n,m = gets.strip.split(' ') | |
n = n.to_i | |
m = m.to_i | |
c = gets.strip | |
c = c.split(' ').map(&:to_i) | |
max_distance = 0 | |
closest_distance = 0 | |
distance = 0 | |
for i in (0...n) | |
closest_distance = n | |
c.each do |space_station| | |
distance = (i - space_station).abs | |
closest_distance = distance if distance < closest_distance | |
break if closest_distance < max_distance | |
end | |
max_distance = closest_distance if closest_distance > max_distance | |
end | |
puts max_distance |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment