Given two linked lists, return the intersection of the two lists: i.e. return a list containing only the elements that occur in both of the input lists.
Anonymous
Traverse the first list. Insert all the elements in the list into a hash table. Complexity: O(n) Traverse the second list. For each element in the list, look it up in the hash table. If it is in the hash table, then insert it into the destination list. Complexity: n * O(1) = O(n) Total complexity: O(n)
Check out your Company Bowl for anonymous work chats.