Skip to content

Instantly share code, notes, and snippets.

@stephen-maina
Created April 13, 2015 14:48
Show Gist options
  • Save stephen-maina/abc19d9c3f6a20b95c89 to your computer and use it in GitHub Desktop.
Save stephen-maina/abc19d9c3f6a20b95c89 to your computer and use it in GitHub Desktop.
MaxCounters Codility...not fast enough though.
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