Last active
December 28, 2015 04:58
-
-
Save straypacket/7445898 to your computer and use it in GitHub Desktop.
Codility - Lesson 2 Frog-River-One (100/100)
Max-Counters (88/100)
This file contains hidden or 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) | |
counter = 0 | |
path = {} | |
if x != nil and a != nil | |
if x > 0 and a.length > 0 | |
pos = 0 | |
a.each do |i| | |
if !path.key?(i) and i <= x | |
counter += 1 | |
end | |
if counter == x | |
return pos | |
end | |
path[i] = true | |
pos += 1 | |
end | |
end | |
end | |
return -1 | |
end |
This file contains hidden or 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(n, a) | |
v = [0] * n | |
max = 0 | |
if n != nil and a != nil | |
if n > 0 and a.length > 0 | |
a.each do |i| | |
if i > n | |
v = Array.new(n,max) | |
else | |
v[i-1] += 1 | |
max = v[i-1] if v[i-1] > max | |
end | |
end | |
end | |
end | |
return v | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment