Challenge - 5 Problems
Reorder List Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of Reorder Linked List After One Operation
Given a singly linked list 1 -> 2 -> 3 -> 4 -> null, what is the list after one reorder operation that moves the last element after the first element?
DSA C#
class Node { public int val; public Node next; public Node(int val=0, Node next=null) { this.val = val; this.next = next; } } // Initial list: 1 -> 2 -> 3 -> 4 -> null // Operation: Move last node after first node Node head = new Node(1, new Node(2, new Node(3, new Node(4)))); // After operation, print list
Attempts:
2 left
💡 Hint
Think about taking the last node and placing it right after the first node.
✗ Incorrect
The reorder operation takes the last node (4) and inserts it after the first node (1), resulting in 1 -> 4 -> 2 -> 3 -> null.
❓ Predict Output
intermediateFinal List After Full Reorder
Given the linked list 1 -> 2 -> 3 -> 4 -> 5 -> null, what is the list after fully applying the reorder list algorithm (L0 → Ln → L1 → Ln-1 → L2 → Ln-2 → ...)?
DSA C#
// Initial list: 1 -> 2 -> 3 -> 4 -> 5 -> null // After reorder: print list
Attempts:
2 left
💡 Hint
The reorder alternates nodes from start and end moving inward.
✗ Incorrect
The reorder list algorithm rearranges nodes as first, last, second, second last, and so on. For 1->2->3->4->5, the result is 1->5->2->4->3.
🔧 Debug
advancedIdentify the Bug in Reorder List Implementation
What error will this C# code produce when trying to reorder the list 1 -> 2 -> 3 -> 4 -> null?
class Node {
public int val;
public Node next;
public Node(int val=0, Node next=null) {
this.val = val;
this.next = next;
}
}
void ReorderList(Node head) {
if (head == null || head.next == null) return;
Node slow = head, fast = head;
while (fast.next != null && fast.next.next != null) {
slow = slow.next;
fast = fast.next.next;
}
Node second = slow.next;
slow.next = null;
second = ReverseList(second);
Node first = head;
while (second != null) {
Node temp1 = first.next;
Node temp2 = second.next;
first.next = second;
second.next = temp1;
first = temp1;
second = temp2;
}
}
Node ReverseList(Node head) {
Node prev = null;
while (head != null) {
Node next = head.next;
head.next = prev;
prev = head;
head = next;
}
return prev;
}
// Call ReorderList(head) with list 1->2->3->4->null
Attempts:
2 left
💡 Hint
Trace the execution step by step for the list 1->2->3->4. Does it crash or produce the correct order 1->4->2->3?
✗ Incorrect
There is no error in the code. It correctly finds the middle, reverses the second half (4->3), cuts the first half (1->2), and merges to produce 1 -> 4 -> 2 -> 3 -> null without any exceptions.
🚀 Application
advancedNumber of Nodes After Reorder
If you apply the reorder list algorithm to a linked list with 7 nodes, how many nodes will the reordered list contain?
Attempts:
2 left
💡 Hint
Reordering changes order but not number of nodes.
✗ Incorrect
Reordering rearranges nodes but does not add or remove any nodes, so the count remains the same.
🧠 Conceptual
expertCorrect Order of Steps in Reorder List Algorithm
What is the correct sequence of steps to reorder a linked list as per the reorder list algorithm?
Attempts:
2 left
💡 Hint
Think about how to split, reverse, then merge.
✗ Incorrect
First find middle, then reverse second half, then merge halves, finally return head.
