Skip to content

Instantly share code, notes, and snippets.

@rafaltrojanowski
Last active November 26, 2017 09:26
Show Gist options
  • Save rafaltrojanowski/ce6690bfb4c960babdf068730d9a5fb7 to your computer and use it in GitHub Desktop.
Save rafaltrojanowski/ce6690bfb4c960babdf068730d9a5fb7 to your computer and use it in GitHub Desktop.
def solution(a)
sum = 0
sum = a.inject(&:+)
l = 0
r = 0
p = 0
ret = nil
a[0..-2].each_with_index do |element|
l += element
r = sum - l
p = (l - r).abs
ret ||= p
ret = p if p < ret
end
ret
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment