Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node with the given data.
DSA Python
new_node = Node([1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that is not defined in the function.
Passing the node instead of the data.
✗ Incorrect
We create a new node by passing the data value to the Node constructor.
2fill in blank
mediumComplete the code to check if the position to insert is at the head (position 1).
DSA Python
if position == [1]:
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for position 0 instead of 1.
Using None or negative numbers for position.
✗ Incorrect
Position 1 means inserting at the head of the doubly linked list.
3fill in blank
hardFix the error in the loop that moves to the node before the insertion point.
DSA Python
for _ in range([1] - 2): current = current.next
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using position - 1 or position - 2 incorrectly causing off-by-one errors.
Using position + 1 which goes too far.
✗ Incorrect
We loop position - 2 times to reach the node before the insertion point.
4fill in blank
hardFill both blanks to correctly insert the new node between nodes.
DSA Python
new_node.next = current.[1] new_node.prev = current current.[2] = new_node
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using prev instead of next causing wrong links.
Using incorrect attribute names like next_node.
✗ Incorrect
We set new_node.next to current.next and then current.next to new_node to insert properly.
5fill in blank
hardFill all three blanks to update the previous pointer of the next node after insertion.
DSA Python
if new_node.next is not None: new_node.next.[1] = new_node return [2] # Function ends here head = [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not updating the prev pointer of the next node.
Returning or assigning the wrong variable.
✗ Incorrect
We update new_node.next.prev to new_node, return head, and assign head to the function call result.