Skip to content

Instantly share code, notes, and snippets.

@oddlyfunctional
Created February 2, 2016 14:59
Show Gist options
  • Save oddlyfunctional/ca721e3c587e45f21979 to your computer and use it in GitHub Desktop.
Save oddlyfunctional/ca721e3c587e45f21979 to your computer and use it in GitHub Desktop.
#!/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