Question d’entretien chez 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

Réponses aux questions d'entretien

Utilisateur anonyme

15 janv. 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).

Utilisateur anonyme

17 janv. 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;