Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the doubly linked list is empty before deletion.
DSA Python
if self.head is [1]: return None
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using True or False instead of None.
Checking if head equals 0.
✗ Incorrect
We check if head is None to know if the list is empty.
2fill in blank
mediumComplete the code to move to the last node in the doubly linked list.
DSA Python
current = self.head while current.[1] is not None: current = current.next
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using prev instead of next to move forward.
Using head or tail which are not node attributes.
✗ Incorrect
We use current.next to move forward through the list until the last node.
3fill in blank
hardFix the error in updating the previous node's next pointer when deleting the last node.
DSA Python
if current.prev is not None: current.prev.[1] = None
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting prev instead of next.
Trying to set head or tail which are not node attributes.
✗ Incorrect
We set the previous node's next pointer to None to remove the last node.
4fill in blank
hardFill both blanks to handle the case when the list has only one node during deletion.
DSA Python
if current.prev is [1] and current.next is [2]: self.head = None
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using True or False instead of None.
Using 0 which is not a pointer.
✗ Incorrect
If both prev and next are None, the list has one node, so head becomes None after deletion.
5fill in blank
hardFill all three blanks to complete the delete from end method in the doubly linked list.
DSA Python
def delete_from_end(self): if self.head is [1]: return None current = self.head while current.[2] is not None: current = current.next if current.prev is not [3]: current.prev.next = None else: self.head = None
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using True or False instead of None.
Mixing up prev and next pointers.
✗ Incorrect
We check if head is None, move using next, and check if prev is None to update pointers correctly.