Question d’entretien chez Bloomberg

Remove duplicates from array in place.

Réponses aux questions d'entretien

Utilisateur anonyme

3 oct. 2015

Sort the array first O(n*log(n)), and then use 2 pointers to modify the array in place.

1

Utilisateur anonyme

29 nov. 2015

Note that the previous answer does not keep the original order of the numbers (which might be required). To keep the order, use auxiliary hash set (unordered set) to check if the coming number is a duplicate or not. And it is O(n) (assuming the frequency of hash collisions is low). Or ordered set for guaranteed O(n * log n) solution. That requires auxiliary structure with O(n) memory, however the sort solution uses auxiliary memory as well (virtually every O(n*logn) runtime sort needs at least O(logn) space, might it be space on the stack).