Challenge - 5 Problems
Node Structure Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of Linked List Node Traversal
What is the printed output of the linked list traversal code below?
DSA C
typedef struct Node {
int data;
struct Node* next;
} Node;
#include <stdio.h>
#include <stdlib.h>
int main() {
Node* head = malloc(sizeof(Node));
head->data = 10;
head->next = malloc(sizeof(Node));
head->next->data = 20;
head->next->next = NULL;
Node* current = head;
while (current != NULL) {
printf("%d -> ", current->data);
current = current->next;
}
printf("NULL\n");
return 0;
}Attempts:
2 left
💡 Hint
Trace the linked list starting from head and follow the next pointers until NULL.
✗ Incorrect
The code creates two nodes linked together: first node with data 10 points to second node with data 20, which points to NULL. Traversal prints 10 then 20 then NULL.
🧠 Conceptual
intermediate1:00remaining
Pointer Usage in Doubly Linked List Node
In a doubly linked list node structure, which pointer is used to access the previous node?
Attempts:
2 left
💡 Hint
Think about which pointer points backward in the list.
✗ Incorrect
The 'prev' pointer in a doubly linked list node points to the previous node, allowing backward traversal.
❓ Predict Output
advanced2:00remaining
Output of Circular Linked List Traversal
What is the output of the following circular linked list traversal code?
DSA C
typedef struct Node {
int data;
struct Node* next;
} Node;
#include <stdio.h>
#include <stdlib.h>
int main() {
Node* head = malloc(sizeof(Node));
head->data = 1;
Node* second = malloc(sizeof(Node));
second->data = 2;
Node* third = malloc(sizeof(Node));
third->data = 3;
head->next = second;
second->next = third;
third->next = head; // circular link
Node* current = head;
int count = 0;
while (count < 5) {
printf("%d -> ", current->data);
current = current->next;
count++;
}
printf("...\n");
return 0;
}Attempts:
2 left
💡 Hint
The last node points back to the head, so traversal loops.
✗ Incorrect
The circular linked list loops through nodes 1, 2, 3 repeatedly. The code prints 5 nodes, so output is 1 2 3 1 2 ...
🔧 Debug
advanced2:00remaining
Identify the Pointer Bug in Node Insertion
What error will occur when running this code to insert a new node at the beginning of a singly linked list?
DSA C
typedef struct Node {
int data;
struct Node* next;
} Node;
#include <stdio.h>
#include <stdlib.h>
void insertAtHead(Node** head, int val) {
Node* newNode = malloc(sizeof(Node));
newNode->data = val;
newNode->next = *head;
*head = newNode;
}
int main() {
Node* head = NULL;
insertAtHead(&head, 5);
printf("%d -> NULL\n", head->data);
return 0;
}Attempts:
2 left
💡 Hint
Check how the head pointer is passed and updated.
✗ Incorrect
The function insertAtHead now receives a pointer to head, so updating *head inside affects main's head pointer. The code prints correctly.
🧠 Conceptual
expert1:30remaining
Memory Layout of a Node with Multiple Pointers
Consider a node structure with three pointers: next, prev, and random (pointing to any node). What is the minimum number of pointers needed to traverse the list in both directions and also jump randomly?
Attempts:
2 left
💡 Hint
Think about what each pointer is used for in traversal and random access.
✗ Incorrect
To traverse forward and backward, next and prev are needed. To jump randomly, a random pointer is required. So minimum is 3 pointers.
