Challenge - 5 Problems
Circular List Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of Circular Linked List Traversal
What is the output of the following C code that traverses a circular linked list with 3 nodes containing values 10, 20, and 30?
DSA C
#include <stdio.h> #include <stdlib.h> struct Node { int data; struct Node* next; }; int main() { struct Node* head = malloc(sizeof(struct Node)); struct Node* second = malloc(sizeof(struct Node)); struct Node* third = malloc(sizeof(struct Node)); head->data = 10; head->next = second; second->data = 20; second->next = third; third->data = 30; third->next = head; // circular link struct Node* temp = head; do { printf("%d -> ", temp->data); temp = temp->next; } while (temp != head); printf("null\n"); free(head); free(second); free(third); return 0; }
Attempts:
2 left
💡 Hint
Look carefully at the loop condition and how the traversal stops when it reaches the head again.
✗ Incorrect
The traversal uses a do-while loop that prints each node's data and stops when it reaches the head node again, so it prints all nodes exactly once.
🧠 Conceptual
intermediate1:00remaining
Number of Nodes Traversed in Circular Linked List
If a circular linked list has 5 nodes, how many nodes will be visited during a traversal that starts at the head and stops when it reaches the head again?
Attempts:
2 left
💡 Hint
Think about how the traversal stops exactly when it reaches the head again after visiting all nodes once.
✗ Incorrect
The traversal visits all 5 nodes exactly once before stopping when it reaches the head again.
🔧 Debug
advanced1:30remaining
Identify the Bug in Circular Linked List Traversal
What error will occur when running this code snippet that attempts to traverse a circular linked list?
DSA C
struct Node* temp = head; while (temp != NULL) { printf("%d -> ", temp->data); temp = temp->next; } printf("null\n");
Attempts:
2 left
💡 Hint
Think about what happens to temp in a circular linked list when checking for NULL.
✗ Incorrect
In a circular linked list, next pointer never becomes NULL, so the while loop condition temp != NULL never becomes false, causing an infinite loop.
❓ Predict Output
advanced2:00remaining
Output After Modifying Circular Linked List
What is the output after inserting a new node with value 15 between nodes with values 10 and 20 in the circular linked list and then traversing it?
DSA C
#include <stdio.h> #include <stdlib.h> struct Node { int data; struct Node* next; }; int main() { struct Node* head = malloc(sizeof(struct Node)); struct Node* second = malloc(sizeof(struct Node)); struct Node* third = malloc(sizeof(struct Node)); struct Node* newNode = malloc(sizeof(struct Node)); head->data = 10; second->data = 20; third->data = 30; newNode->data = 15; head->next = newNode; newNode->next = second; second->next = third; third->next = head; struct Node* temp = head; do { printf("%d -> ", temp->data); temp = temp->next; } while (temp != head); printf("null\n"); free(head); free(second); free(third); free(newNode); return 0; }
Attempts:
2 left
💡 Hint
Check the order of next pointers after insertion.
✗ Incorrect
The new node with 15 is inserted between 10 and 20, so traversal prints 10, 15, 20, 30 in order.
🧠 Conceptual
expert1:30remaining
Detecting Circular Linked List Using Fast and Slow Pointers
Which statement correctly describes how the fast and slow pointer method detects a circular linked list?
Attempts:
2 left
💡 Hint
Think about when two pointers meet in a circular structure.
✗ Incorrect
In a circular linked list, fast and slow pointers eventually meet at the same node, indicating a cycle.
