Microsoft Interview Question
1,274 Interview Reviews |
Back to all Microsoft Interview Questions & Reviews
Interview questions and reviews posted anonymously by interview candidates
Interview Question for Senior Software Developer at Microsoft:
best strategy to take out the duplicate elements in an array
See more for this Microsoft Senior Software Developer Interview
Helpful Question?
Yes |
No
Inappropriate?



0 of 0 people found this helpful
by Tim:
for( element in array):
if( seen.contains( element ) ):
array.erase( element )
Runtime:
* For a tree based set, O( n * log n )
* For a hash table based set, O( n ) assuming no collisions and constant hashing
Improvements: If array.erase isn't efficient (it's an array, it won't be) then keep a collection of pointers or indices into the array to erase in a more efficient manner than 1 at a time.