Pergunta de entrevista da empresa Amazon

In-House interview: 1. Given two int arrays, return a third int array that contains all values in the first int array that aren't in the 2nd. If a value is duplicated in the first int array, only return it once in the output array. 2. Model a deck of cards

Respostas da entrevista

Sigiloso

15 de jan. de 2012

1. Add all values from the 2nd array to a hash table. Go through the 1st array and check the hash. If it's not in there, add it to the output array and to the hash (so it can handle the case where a value is duplicated in the first array).

Sigiloso

17 de jan. de 2012

Put the arrays into Set collection set1 and set2 and do set1.removeall(set2) and return set1. Set mySet1 = new HashSet(Arrays.asList(array1)); Set mySet2 = new HashSet(Arrays.asList(array2)); mySet1.removeAll(mySet2); return mySet1;