Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the result variable for XOR operation.
DSA Python
def find_non_repeating(arr): result = [1] for num in arr: result ^= num return result
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing result with arr[0] causes skipping the first element in XOR.
✗ Incorrect
We start with 0 because XOR with 0 returns the other number unchanged.
2fill in blank
mediumComplete the code to XOR each element with the result.
DSA Python
def find_non_repeating(arr): result = 0 for num in arr: result [1]= num return result
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using + or & instead of ^ changes the logic and output.
✗ Incorrect
The XOR operator is ^ in Python, used to find the unique element.
3fill in blank
hardFix the error in the function call to print the unique element.
DSA Python
arr = [2, 3, 5, 4, 5, 3, 4] print(find_non_repeating[1]arr[2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets or braces instead of parentheses for function calls.
✗ Incorrect
Function calls require parentheses around arguments.
4fill in blank
hardFill both blanks to complete the function that returns the unique element from the list.
DSA Python
def find_non_repeating(arr): result = [1] for num in arr: result [2]= num return result
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of ^ changes the logic.
✗ Incorrect
Initialize result to 0 and use ^= to XOR each element.
5fill in blank
hardFill all three blanks to create a dictionary comprehension that maps each number to its XOR with 1 if it is greater than 2.
DSA Python
result = {num: num[1]1 for num in arr if num [2] 2}
filtered = {k: v for k, v in result.items() if v [3] 0} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using & instead of ^ for XOR, or == instead of != for filtering.
✗ Incorrect
Use XOR (^) with 1, filter numbers greater than 2, and keep those with XOR result not equal to 0.