def solution(x, arr)
k = 0
n = arr.length
condition = -> (a) { a.eql? x}
arr.each_with_index do |a, i|
if arr[0..i-1].select(&condition).size == arr[i..n-1].reject(&condition).size
k = i
break
end
end
k
end
#usage
arr = [5, 5, 1, 7, 2, 3, 5]
x = 5
k = solution(x, arr)
#=> 4
Last active
October 21, 2016 15:12
-
-
Save jonasporto/30d335081a8858e72b2c8dbdca62d3d0 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment