#include <stdio.h>
#define ARR1SIZE 5
#define ARR2SIZE 5
int main()
{
int arr1[] = {6, 3, 6, 1, 7};
int arr2[] = {5, 1, 2, 4, 6};
int arr3[ARR1SIZE + ARR2SIZE];
// Using bit map, All bits are 0
int bitMap = 0;
int bitMask = 0;
int i = 0;
int k = 0;
for (i = 0; i < ARR1SIZE; i++) {
// Check if value already exist
bitMask = 0;
bitMask = 1 << arr1[i];
if (bitMap & bitMask) {
continue;
}
arr3[k++] = arr1[i];
// Mark bitMap that value exist
bitMap |= 1 << arr1[i];
}
for (i = 0; i < ARR2SIZE; i++) {
// Check if value already exist
bitMask = 0;
bitMask = 1 << arr2[i];
if (bitMap & bitMask) {
continue;
}
arr3[k++] = arr2[i];
// Mark bitMap that value exist
bitMap |= 1 << arr2[i];
}
for (i = 0; i < k; i++) {
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgojZGVmaW5lIEFSUjFTSVpFIDUKI2RlZmluZSBBUlIyU0laRSA1CgppbnQgbWFpbigpCnsKICAgIGludCBhcnIxW10gPSB7NiwgMywgNiwgMSwgN307CiAgICBpbnQgYXJyMltdID0gezUsIDEsIDIsIDQsIDZ9OwogICAgaW50IGFycjNbQVJSMVNJWkUgKyBBUlIyU0laRV07CgogICAgLy8gVXNpbmcgYml0IG1hcCwgQWxsIGJpdHMgYXJlIDAKICAgIGludCBiaXRNYXAgPSAwOwogICAgaW50IGJpdE1hc2sgPSAwOwogICAgaW50IGkgPSAwOwogICAgaW50IGsgPSAwOwoKICAgIGZvciAoaSA9IDA7IGkgPCBBUlIxU0laRTsgaSsrKSB7CiAgICAgICAgLy8gQ2hlY2sgaWYgdmFsdWUgYWxyZWFkeSBleGlzdAogICAgICAgIGJpdE1hc2sgPSAwOwogICAgICAgIGJpdE1hc2sgPSAxIDw8IGFycjFbaV07CgogICAgICAgIGlmIChiaXRNYXAgJiBiaXRNYXNrKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgIH0KICAgICAgICBhcnIzW2srK10gPSBhcnIxW2ldOwoKICAgICAgICAvLyBNYXJrIGJpdE1hcCB0aGF0IHZhbHVlIGV4aXN0CiAgICAgICAgYml0TWFwIHw9IDEgPDwgYXJyMVtpXTsKICAgIH0KCiAgICBmb3IgKGkgPSAwOyBpIDwgQVJSMlNJWkU7IGkrKykgewogICAgICAgIC8vIENoZWNrIGlmIHZhbHVlIGFscmVhZHkgZXhpc3QKICAgICAgICBiaXRNYXNrID0gMDsKICAgICAgICBiaXRNYXNrID0gMSA8PCBhcnIyW2ldOwoKICAgICAgICBpZiAoYml0TWFwICYgYml0TWFzaykgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICB9CiAgICAgICAgYXJyM1trKytdID0gYXJyMltpXTsKCiAgICAgICAgLy8gTWFyayBiaXRNYXAgdGhhdCB2YWx1ZSBleGlzdAogICAgICAgIGJpdE1hcCB8PSAxIDw8IGFycjJbaV07CiAgICB9CgogICAgcHJpbnRmKCJNZXJnZWQgQXJyYXlcbiIpOwogICAgZm9yIChpID0gMDsgaSA8IGs7IGkrKykgewogICAgICAgIHByaW50ZigiJWQgIiwgYXJyM1tpXSk7CiAgICB9CgogICAgcmV0dXJuIDA7Cn0K