#include <stdio.h> int main() { int n, m; // Input size of the first array (Tech Wizards) scanf("%d", &n); int arr1[n]; for (int i = 0; i < n; ++i) { scanf("%d", &arr1[i]); } // Input size of the second array (Creative Minds) scanf("%d", &m); int arr2[m]; for (int i = 0; i < m; ++i) { scanf("%d", &arr2[i]); } // Merge and find unique member IDs int merged[n + m]; // Maximum possible size int i = 0, j = 0, k = 0; while (i < n && j < m) { if (arr1[i] < arr2[j]) { merged[k++] = arr1[i++]; } else if (arr1[i] > arr2[j]) { merged[k++] = arr2[j++]; } else { // arr1[i] == arr2[j] merged[k++] = arr1[i++]; j++; } } // Copy remaining elements from arr1 (if any) while (i < n) { merged[k++] = arr1[i++]; } // Copy remaining elements from arr2 (if any) while (j < m) { merged[k++] = arr2[j++]; } // Output the merged and unique member IDs for (int idx = 0; idx < k; ++idx) { if (idx == 0 || merged[idx] != merged[idx - 1]) { printf("%d ", merged[idx]); } } printf("\n"); return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter