Skip to content

Instantly share code, notes, and snippets.

@antonio
Last active July 26, 2017 18:16
Show Gist options
  • Save antonio/1511713 to your computer and use it in GitHub Desktop.
Save antonio/1511713 to your computer and use it in GitHub Desktop.
Codility Demos
def equi ( a )
return -1 if (a.nil? || a.empty?)
lower_sum = 0
higher_sum = 0
a.each { |x| higher_sum += x }
a.each_index do |p|
lower_sum += a[p-1] if p!=0
higher_sum -= a[p]
return p if lower_sum == higher_sum
p += 1
end
return -1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment