Challenge - 5 Problems
Node Structure Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of Linked List Node Connections
What is the printed output of the linked list after running the following code?
DSA Javascript
class Node { constructor(value) { this.value = value; this.next = null; } } const head = new Node(1); head.next = new Node(2); head.next.next = new Node(3); let current = head; let output = ''; while (current) { output += current.value + ' -> '; current = current.next; } output += 'null'; console.log(output);
Attempts:
2 left
💡 Hint
Trace the next pointers from the head node to the end.
✗ Incorrect
The linked list nodes are connected in order: 1 points to 2, 2 points to 3, and 3 points to null. So the output prints values in sequence 1 -> 2 -> 3 -> null.
❓ Predict Output
intermediateOutput of Doubly Linked List Node Values
What is the output after running this doubly linked list traversal code?
DSA Javascript
class Node { constructor(value) { this.value = value; this.next = null; this.prev = null; } } const node1 = new Node(10); const node2 = new Node(20); const node3 = new Node(30); node1.next = node2; node2.prev = node1; node2.next = node3; node3.prev = node2; let current = node3; let output = ''; while (current) { output += current.value + ' <-> '; current = current.prev; } output += 'null'; console.log(output);
Attempts:
2 left
💡 Hint
Start from the last node and follow the prev pointers.
✗ Incorrect
Starting from node3 (value 30), following prev pointers visits node2 (20) then node1 (10), then null. So output is 30 <-> 20 <-> 10 <-> null.
❓ Predict Output
advancedOutput of Circular Linked List Traversal
What will be printed by this code that traverses a circular linked list with 3 nodes?
DSA Javascript
class Node { constructor(value) { this.value = value; this.next = null; } } const nodeA = new Node('A'); const nodeB = new Node('B'); const nodeC = new Node('C'); nodeA.next = nodeB; nodeB.next = nodeC; nodeC.next = nodeA; // circular link let current = nodeA; let output = ''; let count = 0; while (count < 5) { output += current.value + ' -> '; current = current.next; count++; } output += '...'; console.log(output);
Attempts:
2 left
💡 Hint
The list loops back to the start after node C.
✗ Incorrect
The circular link makes traversal repeat nodes A, B, C in a loop. The code prints 5 nodes then '...'. So output is A -> B -> C -> A -> B -> ...
🧠 Conceptual
advancedPointer Design in a Binary Tree Node
Which of the following correctly describes the pointers in a binary tree node structure?
Attempts:
2 left
💡 Hint
Think about how binary trees branch.
✗ Incorrect
A binary tree node typically has two pointers: left child and right child. Parent or sibling pointers are optional and not standard.
❓ Predict Output
expertOutput of Complex Linked List with Random Pointers
Given the following code with nodes having next and random pointers, what is the output of the printed values following the random pointers starting from head?
DSA Javascript
class Node { constructor(value) { this.value = value; this.next = null; this.random = null; } } const node1 = new Node(5); const node2 = new Node(10); const node3 = new Node(15); node1.next = node2; node2.next = node3; node1.random = node3; node2.random = node1; node3.random = node2; let current = node1; let output = ''; let count = 0; while (current && count < 3) { output += current.value + ' -> '; current = current.random; count++; } output += 'null'; console.log(output);
Attempts:
2 left
💡 Hint
Follow the random pointers starting from node1.
✗ Incorrect
Starting at node1 (5), random points to node3 (15), which random points to node2 (10), which random points to node1 but loop stops after 3 steps. So output is 5 -> 15 -> 10 -> null.
