Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to delete the head node of a singly linked list.
DSA Python
def delete_head(head): if head is None: return None new_head = head[1] return new_head
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using .prev which is for doubly linked lists.
Trying to access .data instead of moving the head pointer.
✗ Incorrect
To delete the head node, we return the next node as the new head.
2fill in blank
mediumComplete the code to delete the node at position 2 (0-based index) in a singly linked list.
DSA Python
def delete_at_pos(head, pos): if pos == 0: return head.next current = head for _ in range(pos - 1): current = current[1] current.next = current.next.next return head
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using .prev which does not exist in singly linked lists.
Trying to access .data instead of moving the pointer.
✗ Incorrect
To reach the node before the one to delete, we move using the .next attribute.
3fill in blank
hardFix the error in the code to delete a node at a given position in a singly linked list.
DSA Python
def delete_node(head, pos): if pos == 0: return head.next current = head for i in range(pos - 1): if current is None or current.next is None: return head current = current[1] current.next = current.next.next return head
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using .prev which is not defined in singly linked lists.
Trying to access .data instead of moving the pointer.
✗ Incorrect
The pointer should move to the next node using .next to traverse the list correctly.
4fill in blank
hardFill both blanks to delete the node at position pos in a singly linked list safely.
DSA Python
def delete_node_safe(head, pos): if pos == 0: return head[1] current = head for _ in range(pos - 1): if current is None or current.next is None: return head current = current[2] current.next = current.next.next return head
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using .prev which is not available in singly linked lists.
Trying to access .data instead of moving the pointer.
✗ Incorrect
Both blanks require moving to the next node using .next to traverse and update the list correctly.
5fill in blank
hardFill all three blanks to delete the node at position pos with boundary checks in a singly linked list.
DSA Python
def delete_node_full(head, pos): if pos == 0: return head[1] current = head for _ in range(pos - 1): if current is None or current.next is None: return head current = current[2] if current.next is None: return head current.next = current.next[3] return head
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using .prev which is not defined in singly linked lists.
Trying to access .data instead of moving the pointer.
✗ Incorrect
All blanks require the .next attribute to move through and update the linked list correctly.