#include <iostream>
#include <vector>
using namespace std;
vector<int> findDup2(int a[], int len) {
vector<int> ret;
for(int i = 0; i < len; i++) {
while(a[a[i]] != a[i]) {
swap(a[a[i]], a[i]);
}
}
for (int i = 0; i<len; i++) {
if (a[i] != i) ret.push_back(a[i]);
}
return ret;
}
int main() {
int a[] = {4, 1, 1, 1, 3, 4};
vector<int> vet;
vet = findDup2(a, sizeof(a)/sizeof(a[0]));
for (int i:vet) cout<<i<<" ";
cout << endl;
// your code goes here
int b[] = {0, 1, 0, 1, 2, 2, 4, 1};
vet = findDup2(b, sizeof(b)/sizeof(b[0]));
for (int i:vet) cout<<i<<" ";
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdmVjdG9yPGludD4gZmluZER1cDIoaW50IGFbXSwgaW50IGxlbikgewoJdmVjdG9yPGludD4gcmV0OwoJCglmb3IoaW50IGkgPSAwOyBpIDwgbGVuOyBpKyspIHsKCQl3aGlsZShhW2FbaV1dICE9IGFbaV0pIHsKCQkJc3dhcChhW2FbaV1dLCBhW2ldKTsKCQl9Cgl9CgkKCWZvciAoaW50IGkgPSAwOyBpPGxlbjsgaSsrKSB7CgkJaWYgKGFbaV0gIT0gaSkgcmV0LnB1c2hfYmFjayhhW2ldKTsKCX0KCXJldHVybiByZXQ7Cn0KCmludCBtYWluKCkgewoJaW50IGFbXSA9IHs0LCAxLCAxLCAxLCAzLCA0fTsKCXZlY3RvcjxpbnQ+IHZldDsKCXZldCA9IGZpbmREdXAyKGEsIHNpemVvZihhKS9zaXplb2YoYVswXSkpOwoJZm9yIChpbnQgaTp2ZXQpIGNvdXQ8PGk8PCIgIjsKCWNvdXQgPDwgZW5kbDsKCS8vIHlvdXIgY29kZSBnb2VzIGhlcmUKCQoJaW50IGJbXSA9IHswLCAxLCAwLCAxLCAyLCAyLCA0LCAxfTsKCXZldCA9IGZpbmREdXAyKGIsIHNpemVvZihiKS9zaXplb2YoYlswXSkpOwoJZm9yIChpbnQgaTp2ZXQpIGNvdXQ8PGk8PCIgIjsKCXJldHVybiAwOwp9