Created
March 18, 2015 00:15
-
-
Save kexoth/bc13cd8d7c0684fa7989 to your computer and use it in GitHub Desktop.
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
function solution(N, A) { | |
var counters = new Uint32Array(N), | |
max = 0, | |
gMax = 0; | |
for (i = 0; i < A.length; i++) { | |
var value = A[i]; | |
if (value > N) { | |
max = gMax; | |
} | |
else { | |
var counter = counters[value-1]; | |
if (counter < max) counter = max; | |
counters[value-1] = ++counter; | |
if (counter > gMax) { | |
gMax = counter; | |
} | |
} | |
} | |
for (i = 0; i < N; i++) { | |
if (counters[i] < max) counters[i] = max; | |
} | |
return counters; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment