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 Typescript
current.[1] = temp;Attempts:
3 left
💡 Hint
Common Mistakes
Assigning temp to current.next instead of current.prev.
Trying to assign to current.value which is not a pointer.
✗ Incorrect
We swap the next and prev pointers by assigning temp (original next) to current.prev.
2fill in blank
mediumComplete the code to move the current pointer to the next node in the original list.
DSA Typescript
current = current.[1];Attempts:
3 left
💡 Hint
Common Mistakes
Using current.next which now points backward after swapping.
Using current.head or current.tail which are not node pointers.
✗ Incorrect
After swapping, current.prev points to the next node in the original list, so we move current to current.prev.
3fill in blank
hardComplete the code to update the head pointer inside the loop after swapping pointers.
DSA Typescript
if (temp == null) { head = [1]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using if (temp != null) which skips the last node.
Assigning head = temp which is null.
Assigning head = temp.prev which is undefined.
✗ Incorrect
Inside the loop, after swapping pointers for the last node, temp == null and current is the original tail (new head), so head = current.
4fill in blank
hardFill both blanks to complete the while loop condition and the pointer swap inside the loop.
DSA Typescript
while (current != [1]) { let temp = current.[2]; current.[3] = current.[4]; current.[5] = temp; current = current.[6]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong loop condition like current != head.
Mixing up next and prev pointers during swap.
✗ Incorrect
The loop runs until current is null. We store current.next in temp, swap current.next and current.prev, then move current to current.prev (original next).
5fill in blank
hardFill all three blanks to complete the pointer swap inside the loop of the reverse function.
DSA Typescript
function reverseDoublyLinkedList(head: Node | null): Node | null {
let current = head;
let temp: Node | null = null;
while (current != null) {
temp = current.next;
current.[1] = current.[2];
current.[3] = temp;
if (temp == null) {
head = current;
}
current = temp;
}
return head;
}Attempts:
3 left
💡 Hint
Common Mistakes
Not swapping pointers correctly (e.g., current.next = temp).
Confusing next and prev in the assignments.
✗ Incorrect
temp = current.next (hardcoded), current.next = current.prev, current.prev = temp (pointers swapped), if(temp == null) head = current (update new head), current = temp (move forward).
