Created
May 5, 2015 18:22
-
-
Save stephen-maina/0689842ea440e64902e8 to your computer and use it in GitHub Desktop.
not fast enough
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
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