Pergunta de entrevista da empresa AppFolio
1. Given an array that contains duplicates (except for one value), find the one value that does not have a duplicate in that array. Explain the complexity of your algorithm. So in the array: A = [2, 3, 4, 5, 2, 3, 4] your algorithm should return 5 since that's the value that does not have a duplicate.
2. Explain the process that happens when you type your username and hit submit on a website (HTTP, server/client communication, etc...)
Respostas da entrevista
Use the Xor operator.
//java method below
int nonDup(int A[]){
int result=0;
for(int i=0;i
1. Use a HashMap (I didn't think to do this but looking back that seems like a fast way since it's O(1) to put and get()) You could just loop through the array and put/increment the value for each key in the map. Then loop through the array once more to get the values from the map and see which value is not == 2.
// You don't have to run through the hashmap again
public int notDuplicate(int[] array) {
HashMap map = new HashMap();
int current = array[0];
for (int i : array) {
if (map.get(i) == null) {
map.put(i, true);
current = i;
} else if (map.get(i)) {
map.put(i, false);
}
}
return current;
}