Skip to content

Instantly share code, notes, and snippets.

@fakemonk1
Created March 20, 2017 22:39
Show Gist options
  • Save fakemonk1/155e7ba2b2b6477336718363411647c3 to your computer and use it in GitHub Desktop.
Save fakemonk1/155e7ba2b2b6477336718363411647c3 to your computer and use it in GitHub Desktop.
Codility Demo 2 Solution
//This is 100% marks solution for the demo test PrefixSet https://codility.com/demo/take-sample-test/ps/
import java.util.Hashtable;
class Solution2 {
public int solution(int[] A) {
Hashtable<Integer, Integer> map = new Hashtable<>();
for(int i : A){
if(map.containsKey(i)){
map.put(i, map.get(i) +1);
}else{
map.put(i, 1);
}
}
for(int i= A.length -1 ; i >=0 ; i--){
if( map.get(A[i]) > 1){
continue;
}else{
return i;
}
}
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment