Created
April 13, 2015 14:48
-
-
Save stephen-maina/abc19d9c3f6a20b95c89 to your computer and use it in GitHub Desktop.
MaxCounters Codility...not fast enough though.
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
class Solution { | |
public int[] solution(int N, int[] A) { | |
// write your code in Java SE 8 | |
int length=A.length; | |
int max=N+1; | |
int []result=new int[N]; | |
int maxValue=0; | |
for(int index=0;index<length;index++){ | |
if(A[index]<max){ | |
if(A[index]>=1&&A[index]<=N){ | |
result[A[index]-1]+=1; | |
if(result[A[index]-1]>maxValue){ | |
maxValue=result[A[index]-1]; | |
} | |
} | |
}else{ | |
for(int in=0;in<N;in++){ | |
result[in]=maxValue; | |
} | |
} | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment