Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the XOR result variable.
DSA C
int xor_result = [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing xor_result to 1 or -1 causes incorrect XOR results.
Using NULL is invalid for integer initialization.
✗ Incorrect
We start XOR with 0 because XOR with 0 leaves the number unchanged.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' adds numbers instead of XORing bits.
Using '&' or '|' performs AND or OR, not XOR.
✗ Incorrect
The XOR operator in C is '^'. It combines bits where only one bit is set.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using bitwise NOT (~) instead of negation.
Using addition or logical NOT causes wrong mask.
✗ Incorrect
To find the rightmost set bit, we AND xor_result with its two's complement (-xor_result).
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of XOR causes wrong results.
Using '&' in place of XOR accumulates bits incorrectly.
✗ Incorrect
We check if the element has the set bit using 'set_bit_mask'. Then XOR elements in each group separately.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' prints numbers in descending order.
Using '==' or '!=' is incorrect for ordering.
✗ Incorrect
We print the smaller number first by comparing num1 and num2 with '<'.
