Challenge - 5 Problems
Doubly Linked List Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediateMain advantage of doubly linked list over singly linked list
Which of the following is the main advantage of using a doubly linked list instead of a singly linked list?
Attempts:
2 left
💡 Hint
Think about how nodes are connected and how you can move through the list.
✗ Incorrect
A doubly linked list stores two pointers per node: one to the next node and one to the previous node. This allows easy traversal in both directions, unlike singly linked lists which only allow forward traversal.
❓ Predict Output
intermediateOutput after inserting nodes in doubly linked list
What is the printed state of the doubly linked list after these insertions?
DSA Typescript
class Node { value: number; next: Node | null = null; prev: Node | null = null; constructor(value: number) { this.value = value; } } class DoublyLinkedList { head: Node | null = null; tail: Node | null = null; insertAtEnd(value: number) { const newNode = new Node(value); if (!this.head) { this.head = newNode; this.tail = newNode; } else { this.tail!.next = newNode; newNode.prev = this.tail; this.tail = newNode; } } printList() { let current = this.head; let result = ''; while (current) { result += current.value + ' <-> '; current = current.next; } result += 'null'; console.log(result); } } const dll = new DoublyLinkedList(); dll.insertAtEnd(10); dll.insertAtEnd(20); dll.insertAtEnd(30); dll.printList();
Attempts:
2 left
💡 Hint
Check how nodes are linked when inserted at the end.
✗ Incorrect
Nodes are inserted at the end, so the list prints from head to tail: 10 <-> 20 <-> 30 <-> null.
🔧 Debug
advancedIdentify the bug in backward traversal of doubly linked list
What error will this code produce when trying to print the list backward?
DSA Typescript
class Node { value: number; next: Node | null = null; prev: Node | null = null; constructor(value: number) { this.value = value; } } class DoublyLinkedList { head: Node | null = null; tail: Node | null = null; insertAtEnd(value: number) { const newNode = new Node(value); if (!this.head) { this.head = newNode; this.tail = newNode; } else { this.tail!.next = newNode; newNode.prev = this.tail; this.tail = newNode; } } printBackward() { let current = this.head; let result = ''; while (current) { result += current.value + ' <-> '; current = current.prev; } result += 'null'; console.log(result); } } const dll = new DoublyLinkedList(); dll.insertAtEnd(1); dll.insertAtEnd(2); dll.insertAtEnd(3); dll.printBackward();
Attempts:
2 left
💡 Hint
Check which node is used to start backward traversal.
✗ Incorrect
Backward traversal should start from the tail, but this code starts from head. Since head.prev is null, it prints only the head value and stops.
📝 Syntax
advancedIdentify the syntax error in doubly linked list node insertion
Which option contains the syntax error when inserting a new node at the beginning of a doubly linked list?
DSA Typescript
insertAtBeginning(value: number) {
const newNode = new Node(value);
if (!this.head) {
this.head = newNode;
this.tail = newNode;
} else {
newNode.next = this.head;
this.head.prev = newNode;
this.head = newNode;
}
}Attempts:
2 left
💡 Hint
Look carefully at line endings and punctuation.
✗ Incorrect
In TypeScript, missing semicolons can cause syntax errors or unexpected behavior. The line 'this.head.prev = newNode' is missing a semicolon.
🚀 Application
expertChoosing data structure for undo-redo feature
You want to implement an undo-redo feature in a text editor. Which data structure is best suited and why?
Attempts:
2 left
💡 Hint
Think about how you move back and forth between states.
✗ Incorrect
Undo-redo requires moving backward and forward through changes. Doubly linked lists allow easy traversal in both directions, making them ideal for this feature.
