Bird
0
0
DSA Cprogramming~10 mins

Two Non Repeating Elements in Array 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 XOR result variable.

DSA C
int xor_result = [1];
Drag options to blanks, or click blank then click option'
A1
B0
C-1
DNULL
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing xor_result to 1 or -1 causes incorrect XOR results.
Using NULL is invalid for integer initialization.
2fill in blank
medium

Complete the code to XOR all elements in the array.

DSA C
for (int i = 0; i < n; i++) {
    xor_result = xor_result [1] arr[i];
}
Drag options to blanks, or click blank then click option'
A^
B+
C&
D|
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' adds numbers instead of XORing bits.
Using '&' or '|' performs AND or OR, not XOR.
3fill in blank
hard

Fix the error in finding the rightmost set bit mask.

DSA C
int set_bit_mask = xor_result & [1] xor_result);
Drag options to blanks, or click blank then click option'
A~
B!
C-
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using bitwise NOT (~) instead of negation.
Using addition or logical NOT causes wrong mask.
4fill in blank
hard

Fill both blanks to separate the two unique numbers using the set bit mask.

DSA C
int num1 = 0, num2 = 0;
for (int i = 0; i < n; i++) {
    if (arr[i] & [1]) {
        num1 = num1 [2] arr[i];
    } else {
        num2 = num2 ^ arr[i];
    }
}
Drag options to blanks, or click blank then click option'
Aset_bit_mask
B^
C+
D&
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of XOR causes wrong results.
Using '&' in place of XOR accumulates bits incorrectly.
5fill in blank
hard

Fill in the blank to print the two unique numbers in ascending order.

DSA C
if (num1 [1] num2) {
    printf("%d %d\n", num1, num2);
} else {
    printf("%d %d\n", num2, num1);
}
Drag options to blanks, or click blank then click option'
A<
B>
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' prints numbers in descending order.
Using '==' or '!=' is incorrect for ordering.