Skip to content

Instantly share code, notes, and snippets.

@seniorihor
Created October 31, 2016 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seniorihor/930fa482f50eb1941ed07eff8e300bf7 to your computer and use it in GitHub Desktop.
Save seniorihor/930fa482f50eb1941ed07eff8e300bf7 to your computer and use it in GitHub Desktop.
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