#include <iostream>
#include <vector>
using namespace std;
typedef pair<vector<int>, vector<int>> pvivi;
pvivi findMissingAndDup(int a[], int len) {
vector<int> missing, dup;
for (int i = 0; i < len; i++) {
while (a[a[i]] != a[i])
swap(a[i], a[a[i]]);
}
for (int i = 0; i < len; i++) {
if (a[i] != i) {
missing.push_back(i);
dup.push_back(a[i]);
}
}
return make_pair(missing, dup);
}
int main() {
int a[] = {0, 5, 3, 3, 4, 5};
pvivi p = findMissingAndDup(a, sizeof(a)/sizeof(a[0]));
vector<int> vm = p.first;
vector<int> vd = p.second;
cout << "Missing: ";
for (int i:vm) cout<<i<<" ";
cout << "\nDup: ";
for (int i:vd) cout<<i<<" ";
// your code goes here
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdHlwZWRlZiBwYWlyPHZlY3RvcjxpbnQ+LCB2ZWN0b3I8aW50Pj4gcHZpdmk7Cgpwdml2aSBmaW5kTWlzc2luZ0FuZER1cChpbnQgYVtdLCBpbnQgbGVuKSB7Cgl2ZWN0b3I8aW50PiBtaXNzaW5nLCBkdXA7Cglmb3IgKGludCBpID0gMDsgaSA8IGxlbjsgaSsrKSB7CgkJd2hpbGUgKGFbYVtpXV0gIT0gYVtpXSkKCQkJc3dhcChhW2ldLCBhW2FbaV1dKTsKCX0KCglmb3IgKGludCBpID0gMDsgaSA8IGxlbjsgaSsrKSB7CgkJaWYgKGFbaV0gIT0gaSkgewoJCQltaXNzaW5nLnB1c2hfYmFjayhpKTsKCQkJZHVwLnB1c2hfYmFjayhhW2ldKTsKCQl9Cgl9CglyZXR1cm4gbWFrZV9wYWlyKG1pc3NpbmcsIGR1cCk7Cn0KCmludCBtYWluKCkgewoJaW50IGFbXSA9IHswLCA1LCAzLCAzLCA0LCA1fTsKCXB2aXZpIHAgPSBmaW5kTWlzc2luZ0FuZER1cChhLCBzaXplb2YoYSkvc2l6ZW9mKGFbMF0pKTsKCXZlY3RvcjxpbnQ+IHZtID0gcC5maXJzdDsKCXZlY3RvcjxpbnQ+IHZkID0gcC5zZWNvbmQ7Cgljb3V0IDw8ICJNaXNzaW5nOiAiOwoJZm9yIChpbnQgaTp2bSkgY291dDw8aTw8IiAiOwoJY291dCA8PCAiXG5EdXA6ICI7Cglmb3IgKGludCBpOnZkKSBjb3V0PDxpPDwiICI7CgkvLyB5b3VyIGNvZGUgZ29lcyBoZXJlCglyZXR1cm4gMDsKfQ==