Created
December 10, 2014 09:20
-
-
Save metallurgix/a7bc4dfd5ffd12a5a4c3 to your computer and use it in GitHub Desktop.
Codility-Lesson 2-Challenge 4
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(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