Challenge - 5 Problems
Doubly Linked List Deletion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput after deleting the first node from a doubly linked list
What is the printed state of the doubly linked list after deleting the first node?
DSA Javascript
class Node { constructor(data) { this.data = data; this.prev = null; this.next = null; } } class DoublyLinkedList { constructor() { this.head = null; } append(data) { const newNode = new Node(data); if (!this.head) { this.head = newNode; return; } let current = this.head; while (current.next) { current = current.next; } current.next = newNode; newNode.prev = current; } deleteFromBeginning() { if (!this.head) return; this.head = this.head.next; if (this.head) this.head.prev = null; } printList() { let current = this.head; let result = ''; while (current) { result += current.data + ' <-> '; current = current.next; } result += 'null'; console.log(result); } } const dll = new DoublyLinkedList(); dll.append(10); dll.append(20); dll.append(30); dll.deleteFromBeginning(); dll.printList();
Attempts:
2 left
💡 Hint
Deleting from the beginning removes the first node and updates the head.
✗ Incorrect
Initially, the list is 10 <-> 20 <-> 30 <-> null. After deleting the first node (10), the head moves to 20, so the list becomes 20 <-> 30 <-> null.
🧠 Conceptual
intermediateEffect of deleting from an empty doubly linked list
What happens when you try to delete the first node from an empty doubly linked list?
Attempts:
2 left
💡 Hint
Check the deleteFromBeginning method's first condition.
✗ Incorrect
The method checks if head is null and returns immediately, so no changes or errors occur.
❓ Predict Output
advancedOutput after multiple deletions from beginning
What is the printed state of the doubly linked list after deleting the first node twice?
DSA Javascript
class Node { constructor(data) { this.data = data; this.prev = null; this.next = null; } } class DoublyLinkedList { constructor() { this.head = null; } append(data) { const newNode = new Node(data); if (!this.head) { this.head = newNode; return; } let current = this.head; while (current.next) { current = current.next; } current.next = newNode; newNode.prev = current; } deleteFromBeginning() { if (!this.head) return; this.head = this.head.next; if (this.head) this.head.prev = null; } printList() { let current = this.head; let result = ''; while (current) { result += current.data + ' <-> '; current = current.next; } result += 'null'; console.log(result); } } const dll = new DoublyLinkedList(); dll.append(5); dll.append(15); dll.append(25); dll.deleteFromBeginning(); dll.deleteFromBeginning(); dll.printList();
Attempts:
2 left
💡 Hint
Each deletion removes the current head node.
✗ Incorrect
After first deletion, list is 15 <-> 25 <-> null. After second deletion, list is 25 <-> null.
🔧 Debug
advancedIdentify the bug in deleteFromBeginning method
What is the bug in this deleteFromBeginning method and what will be the output after deleting the first node from list 1 <-> 2 <-> 3 <-> null?
function deleteFromBeginning() {
if (!this.head) return;
this.head = this.head.next;
// Missing line here
}
// After calling deleteFromBeginning, printList() is called.
Attempts:
2 left
💡 Hint
Check if the prev pointer of the new head is updated.
✗ Incorrect
The method forgets to set the prev pointer of the new head to null, so the list's backward links remain incorrect.
🧠 Conceptual
expertTime complexity of deleting from beginning in doubly linked list
What is the time complexity of deleting the first node from a doubly linked list and why?
Attempts:
2 left
💡 Hint
Deleting from the beginning does not require visiting all nodes.
✗ Incorrect
Only the head pointer and the prev pointer of the new head are updated, which takes constant time.
