Skip to content

Instantly share code, notes, and snippets.

@straypacket
Last active December 28, 2015 04:58
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 straypacket/7445898 to your computer and use it in GitHub Desktop.
Save straypacket/7445898 to your computer and use it in GitHub Desktop.
Codility - Lesson 2 Frog-River-One (100/100) Max-Counters (88/100)
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
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