Skip to content

Instantly share code, notes, and snippets.

@stephen-maina
Created May 5, 2015 18:22
Show Gist options
  • Save stephen-maina/0689842ea440e64902e8 to your computer and use it in GitHub Desktop.
Save stephen-maina/0689842ea440e64902e8 to your computer and use it in GitHub Desktop.
not fast enough
import java.util.stream.IntStream;
import java.util.stream.Collectors;
import java.util.List;
import java.util.Arrays;
class Solution {
public int[] solution(int[] A) {
// write your code in Java SE 8
int result[]=new int[A.length];
List<Integer> sorted=IntStream.of(A).sorted().boxed().collect(Collectors.toList());
for(int index=0;index<A.length;index++){
int start=0;
int indexOf=sorted.lastIndexOf(A[index]);
int count=sorted.size()-1-indexOf;
for(int x=1;x<=indexOf;x++){
if(sorted.get(indexOf)!=sorted.get(indexOf-x)&&sorted.get(indexOf)%sorted.get(indexOf-x)!=0){
count++;
}
}
result[index]=count;
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment