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

Sigiloso

19 de jul. de 2015

Use the Xor operator. //java method below int nonDup(int A[]){ int result=0; for(int i=0;i

4

Sigiloso

24 de jan. de 2014

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.

3

Sigiloso

6 de out. de 2014

// 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; }

1