Pergunta de entrevista da empresa Google

Given two int arrays. Find out common numbers and different numbers.

Respostas da entrevista

Sigiloso

25 de ago. de 2015

Scan the first array , store them in hashset, scan the second array , check if the number is present in the set (which is o(1) complexity) if it is then its a common number and if its not then its a different number.

Sigiloso

10 de jun. de 2017

void findDiff (array arr1, array arr2) { unordered_set hash; unordered_set::iterator it; int i = 0, k = 0; //used to traverse both arrays in while loops while( i != arr1.end()) { if ( arr1[i] == NULL) { i++; } else hash.insert(arr1[i]); i++; } for( it = hash.begin(); it != hash.end(); it++) { if(arr[k] == NULL) { k++; } if( hash.find(arr2[k]) == hash.end()) { hash.insert(arr2[k]); k++; } else hash.erase(arr2[k]); k++; } for (it = hash.begin(); it != hash.end(); it++) { cout << it* << endl; }

Sigiloso

10 de jun. de 2017

The above didn't let me post the STL, but it uses "array" which if this doesn't show know that it's the STL container for array with an int definition: " array arr1" for example.