Describe an algorithm that will take in a large input of English words that may contain duplicate. Then return only unique words from the input.
Respostas da entrevista
Sigiloso
3 de dez. de 2018
Put the items in a hash map, then return the hash map. Since hashmap eliminates duplicates.
5
Sigiloso
8 de abr. de 2019
Use a set since they don't allow for duplicates and have arbitrary order. Implement the set using a hashtable for constant time checks to see if the word is already in it.
1
Sigiloso
23 de set. de 2019
Sort the array, and then loop through each loop. This should result in a O(n) + O(n) vs O(n^2)
Sigiloso
24 de set. de 2019
In python you could do this with
Def interview(x):
#[str] -> [str]
Return set(x)
Could also use collections.Counter
Then loop through key value pairs
Sigiloso
6 de nov. de 2019
C#, put them into a SortedSet. It will only show the distinct ones.
Sigiloso
20 de fev. de 2019
I was interviewed today and they asked this question, so you can probably expect it!
My solution was to use a linked list to store the words, and with every new word you would conduct a linear search and discard it if it was a duplicate. Horribly inefficient and I am pinching myself for not remember my hashtables :(