Created
March 20, 2017 22:39
-
-
Save fakemonk1/155e7ba2b2b6477336718363411647c3 to your computer and use it in GitHub Desktop.
Codility Demo 2 Solution
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
//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