Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the linked list is empty before deletion.
DSA Python
if self.head is [1]: return
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or False instead of None to check for empty list.
✗ Incorrect
We check if self.head is None to see if the list is empty.
2fill in blank
mediumComplete the code to delete the head node if it contains the target value.
DSA Python
if self.head.data == [1]: self.head = self.head.next return
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using undefined variable names like 'value' or 'data' instead of 'target'.
✗ Incorrect
The variable target holds the value to delete.
3fill in blank
hardFix the error in the while loop condition to traverse the list correctly.
DSA Python
while current is not [1] and current.data != target: prev = current current = current.next
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using True or False instead of None in the loop condition.
✗ Incorrect
The loop should continue while current is not None, meaning nodes remain.
4fill in blank
hardFill both blanks to correctly remove the node by updating links.
DSA Python
if current is not None: [1].next = [2].next
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names or trying to delete the head here.
✗ Incorrect
We set prev.next to skip the current node, effectively deleting it.
5fill in blank
hardFill all three blanks to complete the delete_node method.
DSA Python
def delete_node(self, [1]): if self.head is None: return if self.head.data == [2]: self.head = self.head.next return prev = self.head current = self.head.next while current is not None and current.data != [3]: prev = current current = current.next if current is not None: prev.next = current.next
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing variable names for the target value.
Using undefined variables.
✗ Incorrect
The method parameter is target, the value to delete. We compare self.head.data with target, and in the loop, we compare current.data with target.