Skip to content

Instantly share code, notes, and snippets.

@metallurgix
Created December 10, 2014 09:20
Show Gist options
  • Save metallurgix/a7bc4dfd5ffd12a5a4c3 to your computer and use it in GitHub Desktop.
Save metallurgix/a7bc4dfd5ffd12a5a4c3 to your computer and use it in GitHub Desktop.
Codility-Lesson 2-Challenge 4
def solution(n, a)
max=0
b=Array.new(n,0)
(0..a.length-1).each do |i|
if a[i]>n
b.fill(max)
else
b[a[i]-1]+=1
if b[a[i]-1]>max
max=b[a[i]-1]
end
end
end
b
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment