0
0
DSA Pythonprogramming~10 mins

Delete Node at Specific Position in DSA Python - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A.data
B.prev
C.next
D.head
Attempts:
3 left
💡 Hint
Common Mistakes
Using .prev which is for doubly linked lists.
Trying to access .data instead of moving the head pointer.
2fill in blank
medium

Complete 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'
A.prev
B.next
C.data
D.head
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.
3fill in blank
hard

Fix 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'
A.next
B.head
C.data
D.prev
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.
4fill in blank
hard

Fill 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'
A.next
B.prev
C.data
D.head
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.
5fill in blank
hard

Fill 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'
A.next
B.prev
D.data
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.