Pergunta de entrevista da empresa Amazon

Find Common elements from two same sized Integer Arrays(Unsorted) in O(n) without sorting either of them.

Respostas da entrevista

Sigiloso

18 de set. de 2010

Hash 1 Array 1 Look up for each element in Array 2 Append to common element array if found. O(N)

5

Sigiloso

24 de ago. de 2010

That is N*N complexity, cleverly disguised as single loop. Resetting i every time it reaches N and incrementing j does it.

4

Sigiloso

18 de ago. de 2010

#include main() { //take arrays of three elements for comparision int a[3]={1,2,3}; int b[3]={1,4,2}; int i,j; j=0; for(i=0;i<3;i++) { if(a[i]==b[j]) { printf("common elements are:%d\n",a[i]); } if(i==2&j!=2) { i=0; j++; } } }

1