Pergunta de entrevista da empresa Google

find the intersection of two integer arrays in increasing order.

Resposta da entrevista

Sigiloso

8 de dez. de 2009

Simple O(n log n) solution: Sort the arrays individually, then compare. O(n) solution: Hash the elements in the first array to a hash table. Walk through the second array. If an element in the second array is in the hash table, add the element to a priority queue where priority = ~ value. Read the elements out of the priority queue. We could also use a bit array instead of a priority queue for unique, nonnegative integers.