Pergunta de entrevista da empresa Amazon

Please code up and send me a function that takes two integer arrays and returns their intersection. This answer must take less than n^2 time.

Respostas da entrevista

Sigiloso

5 de nov. de 2010

Use a hash table or tree.

Sigiloso

26 de mai. de 2011

modify merge sort

Sigiloso

20 de dez. de 2013

sample outline of O(n log n) algorithm : a.sort(); b.sort(); list c={}; int i1=0,i2=0; while(true) { if(i1==n || i2==n) break; if(a[i1]==b[i2]) { c.insert(a[i1]); i1++; i2++; }else { if(a[i1] < b[i2]) i1++; else i2++; } } return c;