Pregunta de entrevista de 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.

Respuestas de entrevistas

Anónimo

5 nov 2010

Use a hash table or tree.

Anónimo

26 may 2011

modify merge sort

Anónimo

20 dic 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;