Pergunta de entrevista da empresa Bloomberg

Remove duplicates from array in place.

Respostas da entrevista

Sigiloso

3 de out. de 2015

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

1

Sigiloso

29 de nov. de 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).