Pregunta de entrevista
Entrevista de Machine Learning Developer
-
AmazonPlease 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.
Respuesta
Respuestas de entrevistas
3 respuestas
▲
0
▼
Use a hash table or tree.
Anónimo en
▲
0
▼
modify merge sort
Student en
▲
0
▼
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;
Ali en
Añadir respuestas o comentarios
Para publicar un comentario sobre esto, inicia sesión o regístrate.