Created
October 31, 2016 10:43
-
-
Save seniorihor/930fa482f50eb1941ed07eff8e300bf7 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(arr) | |
index = 0 | |
while index < arr.count do | |
left_s = (index-1) >= 0 ? arr.slice(0..(index-1)).reduce(0, :+) : 0 | |
right_s = arr.slice((index+1)..(arr.count-1)).reduce(0, :+) | |
return index if left_s == right_s | |
index +=1 | |
end | |
return -1 | |
end | |
p solution([1,2,1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment