Last active
November 26, 2017 09:24
-
-
Save rafaltrojanowski/d54031e432cca8bc93fb7161c9b67479 to your computer and use it in GitHub Desktop.
MaxCounters
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) | |
arr = [0] * n | |
max = 0 | |
a.each do |element| | |
if element <= n | |
arr[element-1] += 1 | |
if arr[element-1] > max | |
max = arr[element-1] | |
end | |
else | |
arr = [max] * n | |
end | |
end | |
arr | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment