Zig-Zag World of Algorithm and Data Structures
Home
(Move to ...)
Home
Basic Data Structures
Advance Data Structures
Algorithms
Exercises
Interview Questions
Puzzles
Design Questions
Conferences and Papers
About The Blog
▼
Thursday, August 4, 2011
Salesforce Question: Given two arrays A and B, find out elments of B which are not in A
Hash all the elements of A.
if B[i] is not in hash add into the result. 0<=i<sizeof(B)
Salesforce Question: In an unsorted array, find a pair (a, b) such that a+b = k
It was given that pair will be unique.
void FindPair(int* arr, int size, int sum)
{
for(int i=0; i<size; ++i)
hash[arr[i]] = 1;
for(int i=0; i<size; ++i)
{
if(hash[sum-arr[i]])
cout<<"Pair found ( " <<arr[i]<<", "<<sum-arr[i]<<" )";
}
}
‹
›
Home
View web version