Last active
November 26, 2017 09:26
-
-
Save rafaltrojanowski/ce6690bfb4c960babdf068730d9a5fb7 to your computer and use it in GitHub Desktop.
This file contains 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
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