Bird
0
0
DSA Cprogramming~10 mins

Find the Only Non Repeating Element Using XOR in DSA C - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to initialize the variable that will hold the XOR result.

DSA C
int unique = [1];
Drag options to blanks, or click blank then click option'
A-1
B1
C0
DNULL
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing unique with 1 or -1 causes wrong results.
2fill in blank
medium

Complete the for loop to iterate over the array elements.

DSA C
for (int i = 0; i [1] n; i++) {
    unique ^= arr[i];
}
Drag options to blanks, or click blank then click option'
A<=
B>=
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= causes out-of-bounds access.
3fill in blank
hard

Fix the error in the XOR operation inside the loop.

DSA C
unique [1] arr[i];
Drag options to blanks, or click blank then click option'
A^=
B-=
C+=
D*=
Attempts:
3 left
💡 Hint
Common Mistakes
Using + or - instead of XOR.
4fill in blank
hard

Fill both blanks to complete the function signature and return statement.

DSA C
int findUnique(int [1][], int [2]) {
    int unique = 0;
    for (int i = 0; i < n; i++) {
        unique ^= arr[i];
    }
    return unique;
}
Drag options to blanks, or click blank then click option'
Aarr
Barray
Cn
Dsize
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent variable names causes errors.
5fill in blank
hard

Fill all three blanks to complete the main function that calls findUnique and prints the result.

DSA C
#include <stdio.h>

int findUnique(int arr[], int n);

int main() {
    int arr[] = {2, 3, 5, 4, 5, 3, 4};
    int n = sizeof(arr) / sizeof([1]);
    int unique = findUnique(arr, [2]);
    printf("Unique element is %[3]d\n", unique);
    return 0;
}
Drag options to blanks, or click blank then click option'
Aarr[0]
Bn
Cd
Di
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong format specifier or wrong size calculation.