Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if there is any element in the second list that is an element of the first list (fixed list) ?
Algorithm:
- In this method, we store all elements of second array in a hash table (unordered_set). One by one check all elements of first array and print all those elements which are not present in the hash table.
Example:
#include<stdio.h>
// C++ efficient program to
// find elements which are not
// present in second array
#include<bits/stdc++.h>
using namespace std;
// Function for finding elements which are there in a[] but not in b[].
void findMissing(int a[], int b[],
int n, int m)
{
// Store all elements of
// second array in a hash table
unordered_set s;
for (int i = 0; i < m; i++)
s.insert(b[i]);
// Print all elements of first array that are not present in hash table
for (int i = 0; i < n; i++)
if (s.find(a[i]) == s.end())
cout << a[i] << " ";
}
// Driver code
int main()
{
int a[] = { 1, 2, 6, 3, 4, 5 };
int b[] = { 2, 4, 3, 1, 0 };
int n = sizeof(a) / sizeof(a[0]);
int m = sizeof(b) / sizeof(b[1]);
findMissing(a, b, n, m);
return 0;
}
Output:
Categorized in:
Tagged in:
Accenture interview questions and answers, Applied Materials interview questions and answers, Atos interview questions and answers, BMC Software interview questions and answers, Bosch India Software interview questions and answers, C Program to Find Missing Number in Array, C Program to identify missing Numbers in a given Array, C Program To Identify the Missing Number in an Integer Array, CASTING NETWORKS INDIA PVT LIMITED interview questions and answers, Chetu interview questions and answers, Ciena Corporation interview questions and answers, Dell International Services India Pvt Ltd interview questions and answers, eInfochips interview questions and answers, Electronics Arts Inc interview questions and answers, find all pairs in array, find k missing numbers in an array, find missing and duplicate number in array, find missing number in a sequence, find missing number in array, find missing number in array c, find missing number in array of numbers 1-1000, find missing number in array of size n containing numbers from 1 to n only, find missing number in sorted array, Find the Missing Number, Find the missing number in a sorted array of limited range, Find the repeating and the missing, Flipkart interview questions and answers, for each element in 1st array count elements less than or equal to it in 2nd array, Harman International interview questions and answers, How to Find Missing Number on Integer Array of 1 to 100, How to find missing numbers in arrays in C language, Indecomm Global Services interview questions and answers, Larsen & Toubro interview questions and answers, Mathworks India Private Limited interview questions and answers, Mavenir interview questions and answers, Missing Number in Array, Mphasis interview questions and answers, NetApp interview questions and answers, Oracle Corporation interview questions and answers, PeopleStrong interview questions and answers, Philips Software Centre Pvt Ltd interview questions and answers, program to find missing number in an array, repeat and missing number array, SRM Technologies interview questions and answers, Symphony Teleca interview questions and answers, Tech Mahindra interview questions and answers, Tecnotree interview questions and answers, Wipro Infotech interview questions and answers, Wipro interview questions and answers, Yash Technologies interview questions and answers, ZS Associates interview questions and answers