Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing unique with 1 or -1 causes wrong results.
✗ Incorrect
We start with 0 because XOR with 0 leaves the number unchanged.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= causes out-of-bounds access.
✗ Incorrect
The loop runs from 0 to n-1, so the condition is i < n.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using + or - instead of XOR.
✗ Incorrect
XOR assignment operator ^= is used to combine bits.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent variable names causes errors.
✗ Incorrect
The function takes an array named arr and its size n.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong format specifier or wrong size calculation.
✗ Incorrect
sizeof(arr[0]) gives size of one element, n is passed as array size, and %d is format specifier for int.
