We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
std::vector<int> vecMissingNumbers;
std::array<int, 101> arrFrequency{0};
//Find minimum element in brr
int minBrr = *std::min_element(brr.begin(), brr.end());
cout << "Min = " << minBrr;
//Store frequency in an array with index relative to the smallest number in brr
for(int number: brr)
{
int index = number - minBrr;
cout << index << " ";
arrFrequency.at(index)++;
}
//Subtract count from frequency array based on arr
for(int number: arr)
{
int index = number - minBrr;
cout << index << " ";
arrFrequency.at(index)--;
}
//Check non-zero frequency and store in vector
for(int index = 0; index < 100; index++)
{
if(arrFrequency.at(index) != 0)
{
vecMissingNumbers.push_back(index+minBrr);
}
}
return vecMissingNumbers;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Missing Numbers
You are viewing a single comment's thread. Return to all comments →
C++ Solution:
vector missingNumbers(vector arr, vector brr) {
}