Bloomberg Interview Question

Given a vector of integer elements. Remove the duplicates. Do not change the order of elements.

Interview Answers

Anonymous

Jul 31, 2017

If you are using Java, LinkedHashSet class can be used to achieve the same

1

Anonymous

Apr 19, 2018

Just make a hashmap and check if the key exists and if it does delete the element and if it doesnt add it to the hashmap as a key with a boolean true

Anonymous

Jul 6, 2017

I did it wrong. I realized later you can iterate through the vector once and store in a map, if element is present or not. Iterate through the vector again and each time check if the element is present as a key in the map. First encounter, delete the key val pair from the map. So that the next time same element appears in the vector, it would not be found in the map, so remove the element from the vector and shift all the subsequent vector elements backwards.