0
0
DSA Pythonprogramming~10 mins

Reverse a Doubly Linked List 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 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'
Acurrent.prev
Bcurrent.next
Chead
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning current.next to current.next instead of current.prev.
Using head or None instead of current.prev.
2fill in blank
medium

Complete 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'
Acurrent.prev
Bcurrent.next
Chead
Dtail
Attempts:
3 left
💡 Hint
Common Mistakes
Using current.next which now points backward after swapping.
Using head or tail instead of moving current.
3fill in blank
hard

Fix 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'
Ahead
Bcurrent
Cprev
Dtail
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning head to current which is None.
Assigning head to tail or head itself.
4fill in blank
hard

Fill 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'
Acurrent
Bprev
Ccurrent.prev
Dcurrent.next
Attempts:
3 left
💡 Hint
Common Mistakes
Updating prev to prev or current.next incorrectly.
Moving current to current.next which is swapped.
5fill in blank
hard

Fill 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'
Acurrent
Bcurrent.prev
Cprev
Dhead
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.