Bird
0
0
DSA Cprogramming~20 mins

Reorder Linked List in DSA C - Practice Problems & Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Reorder Linked List Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of Reorder Linked List Function
What is the printed linked list after running the reorder function on the list 1 -> 2 -> 3 -> 4 -> 5 -> null?
DSA C
typedef struct Node {
    int val;
    struct Node* next;
} Node;

void reorderList(Node* head) {
    if (!head || !head->next) return;
    Node *slow = head, *fast = head;
    while (fast && fast->next) {
        slow = slow->next;
        fast = fast->next->next;
    }
    Node* prev = NULL;
    Node* curr = slow->next;
    slow->next = NULL;
    while (curr) {
        Node* nextTemp = curr->next;
        curr->next = prev;
        prev = curr;
        curr = nextTemp;
    }
    Node* first = head;
    Node* second = prev;
    while (second) {
        Node* tmp1 = first->next;
        Node* tmp2 = second->next;
        first->next = second;
        second->next = tmp1;
        first = tmp1;
        second = tmp2;
    }
}

// After reorderList, print list from head to null
// Expected output format: "1 -> 5 -> 2 -> 4 -> 3 -> null"
A1 -> 3 -> 2 -> 5 -> 4 -> null
B1 -> 4 -> 2 -> 5 -> 3 -> null
C1 -> 2 -> 3 -> 4 -> 5 -> null
D1 -> 5 -> 2 -> 4 -> 3 -> null
Attempts:
2 left
💡 Hint
Think about splitting the list into two halves, reversing the second half, then merging alternately.
🧠 Conceptual
intermediate
1:00remaining
Understanding the Purpose of Slow and Fast Pointers
In the reorder linked list algorithm, what is the main purpose of using slow and fast pointers?
ATo find the middle node of the linked list efficiently
BTo reverse the linked list in place
CTo merge two linked lists alternately
DTo detect if the linked list has a cycle
Attempts:
2 left
💡 Hint
Slow moves one step, fast moves two steps.
🔧 Debug
advanced
1:30remaining
Identify the Bug in Reversing the Second Half
Given the following code snippet to reverse the second half of a linked list, what is the bug that causes incorrect reversal?
DSA C
Node* prev = NULL;
Node* curr = slow->next;
slow->next = NULL;
while (curr) {
    Node* nextTemp = curr->next;
    curr->next = prev;
    prev = curr;
    // Missing update of curr here
}
// prev should be the head of reversed list
AThe 'slow->next' should not be set to NULL before reversal
BThe pointer 'prev' is not initialized to NULL
CThe pointer 'curr' is not updated inside the loop, causing an infinite loop
DThe reversal logic is correct; no bug present
Attempts:
2 left
💡 Hint
Check if the loop moves forward properly.
🚀 Application
advanced
1:30remaining
Reordering an Even Length Linked List
What is the reordered linked list after applying the reorderList function on 10 -> 20 -> 30 -> 40 -> null?
A10 -> 40 -> 20 -> 30 -> null
B10 -> 20 -> 30 -> 40 -> null
C10 -> 30 -> 20 -> 40 -> null
D40 -> 10 -> 30 -> 20 -> null
Attempts:
2 left
💡 Hint
Split the list, reverse second half, then merge alternately.
📝 Syntax
expert
1:30remaining
Correct Order of Steps in Reorder Linked List Algorithm
Select the correct sequence of steps to reorder a linked list as per the standard algorithm.
A2,1,3,4
B1,3,2,4
C1,2,3,4
D3,1,2,4
Attempts:
2 left
💡 Hint
Think about finding middle first, then splitting, then reversing second half.