Deshaw Inc Interview Question
Software Engineer / DevelopersIf we know the range of numbers existing in this array (lets say m to n) then we can have an Hash Table with indexes m to n with all items set to zero(0) to start off with. Now, run through the given array and set the corresponding items to true (1) in the hash table. If the value in hash table already = 1 then don't print that item in the array and move ahead. This way we we can print the array elements skipping the duplicates in linear time.
In java, I think you can add the array elements to a Set (this data structure does not allow duplicates) and print the contents of the array
- Ashok August 08, 2009I'm completely new to data structures, correct me if I'm wrong.