I'm trying to find the difference of these 2 sets {1,2,3,4,5,6} and
{1, 3, 6, 4, 1, 2} . The missing
vector should contain just {5} but it contains {2,4,5} . What am I doing wrong here ?
#include <set>
#include <vector>
#include <iostream>
using namespace std;
int solution(vector<int> &A) {
vector<int> missing;
vector<int> range(A.size());
for(int i=1; i<= A.size(); i++) range[i-1] = i;
set_difference(range.begin(), range.end(), A.begin(), A.end(), std::inserter(missing, missing.end()));
return missing[0]; // Missing contains 2,4,5 where as it should had contain just 5
}
int main(){
vector<int> A = {1, 3, 6, 4, 1, 2};
cout << solution(A);
return 0;
}