Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to swap the next and prev pointers of the current node.
DSA Python
current.next, current.prev = current.prev, [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning current.next to current.next instead of current.prev.
Using head or None instead of current.prev.
✗ Incorrect
Swapping current.next and current.prev requires assigning current.prev to current.next and current.next to current.prev. Here, current.next is assigned to current.prev.
2fill in blank
mediumComplete the code to move to the next node in the original list during reversal.
DSA Python
current = [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using current.next which now points backward after swapping.
Using head or tail instead of moving current.
✗ Incorrect
After swapping next and prev, the original next node is now current.prev, so we move current to current.prev.
3fill in blank
hardFix the error in updating the head pointer after reversal.
DSA Python
if current is None: head = [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning head to current which is None.
Assigning head to tail or head itself.
✗ Incorrect
When current becomes None, prev points to the new head of the reversed list, so head should be updated to prev.
4fill in blank
hardFill both blanks to complete the reversal loop and update pointers correctly.
DSA Python
while current is not None: current.next, current.prev = current.prev, current.next prev = [1] current = [2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Updating prev to prev or current.next incorrectly.
Moving current to current.next which is swapped.
✗ Incorrect
Inside the loop, prev is updated to current before moving current to current.prev (the original next node after swapping).
5fill in blank
hardFill all three blanks to create a function that reverses a doubly linked list and returns the new head.
DSA Python
def reverse_doubly_linked_list(head): current = head prev = None while current is not None: current.next, current.prev = current.prev, current.next prev = [1] current = [2] if current is None: head = [3] return head
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using current.next instead of current.prev for moving current.
Not updating head to prev after reversal.
Assigning prev incorrectly inside the loop.
✗ Incorrect
Inside the loop, prev is updated to current, current moves to current.prev (original next), and after loop, head is updated to prev.