Created
December 10, 2014 08:54
-
-
Save metallurgix/1a22b244b7ea79c1d3ce to your computer and use it in GitHub Desktop.
Codility-Lesson 2-Challenge 2
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(x, a) | |
sum=(x*(x+1))/2 | |
pos=-1 | |
b=Array.new(x,0) | |
(0..a.length-1).each do |i| | |
if b[a[i]-1]==0 | |
b[a[i]-1]=1 | |
sum-=a[i] | |
if sum==0 | |
pos=i | |
break | |
end | |
end | |
end | |
pos | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment