Bird
Raised Fist0
DSA C#programming~20 mins

Reorder Linked List in DSA C# - Practice Problems & Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Reorder 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 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
A4 -> 1 -> 2 -> 3 -> null
B1 -> 4 -> 2 -> 3 -> null
C1 -> 2 -> 3 -> 4 -> null
D1 -> 3 -> 4 -> 2 -> null
Attempts:
2 left
💡 Hint
Think about taking the last node and placing it right after the first node.
❓ Predict Output
intermediate
2:00remaining
Final 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
A1 -> 4 -> 2 -> 5 -> 3 -> null
B5 -> 1 -> 4 -> 2 -> 3 -> null
C1 -> 2 -> 3 -> 4 -> 5 -> null
D1 -> 5 -> 2 -> 4 -> 3 -> null
Attempts:
2 left
💡 Hint
The reorder alternates nodes from start and end moving inward.
🔧 Debug
advanced
3:00remaining
Identify 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
ANo error, code runs correctly and reorders the list
BStackOverflowException due to infinite recursion in ReverseList
CNullReferenceException when first becomes null in the merge loop
DCompilation error due to missing return type in ReorderList
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?
🚀 Application
advanced
1:00remaining
Number 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?
ADepends on the values of the nodes
B6 nodes
C7 nodes
D8 nodes
Attempts:
2 left
💡 Hint
Reordering changes order but not number of nodes.
🧠 Conceptual
expert
2:00remaining
Correct 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?
A1,2,3,4
B2,1,3,4
C3,2,1,4
D1,3,2,4
Attempts:
2 left
💡 Hint
Think about how to split, reverse, then merge.

Practice

(1/5)
1. What is the main goal of the Reorder Linked List problem?
easy
A. Reverse the entire linked list
B. Sort the linked list in ascending order
C. Rearrange the list so nodes alternate from start and end
D. Remove duplicate nodes from the list

Solution

  1. Step 1: Understand the problem statement

    The problem asks to reorder the linked list so that nodes are arranged by alternating from the start and the end of the list.
  2. Step 2: Differentiate from other operations

    This is not sorting or reversing the whole list, but a specific pattern: first node, last node, second node, second last node, and so on.
  3. Final Answer:

    Rearrange the list so nodes alternate from start and end -> Option C
  4. Quick Check:

    Reorder means alternate start and end nodes [OK]
Hint: Reorder means alternate nodes from front and back [OK]
Common Mistakes:
  • Confusing reorder with sorting
  • Thinking reorder means full reversal
  • Ignoring the alternating pattern
2. Which of the following C# code snippets correctly declares a singly linked list node class used in reorder linked list problems?
easy
A. public class ListNode { public int val; public ListNode next; public ListNode(int x) { val = x; next = null; } }
B. class Node { int val; Node next; Node(int x) { val = x; next = null; } }
C. public struct ListNode { public int val; public ListNode next; }
D. public class ListNode { int val; ListNode next; ListNode(int x) { val = x; next = null; } }

Solution

  1. Step 1: Check for public accessibility and constructor

    public class ListNode { public int val; public ListNode next; public ListNode(int x) { val = x; next = null; } } correctly declares a public class with public fields and a constructor initializing value and next pointer.
  2. Step 2: Identify missing public keywords and struct misuse

    Options A and D miss public keywords making fields inaccessible; C uses struct which is not typical for linked list nodes.
  3. Final Answer:

    public class ListNode { public int val; public ListNode next; public ListNode(int x) { val = x; next = null; } } -> Option A
  4. Quick Check:

    Public class with constructor and public fields [OK]
Hint: Use public class with constructor and public fields [OK]
Common Mistakes:
  • Omitting public keyword for fields
  • Using struct instead of class
  • Missing constructor initialization
3. Given the linked list: 1 -> 2 -> 3 -> 4 -> 5 -> null, what will be the list after applying the reorder linked list algorithm?
medium
A. 1 -> 5 -> 2 -> 4 -> 3 -> null
B. 5 -> 4 -> 3 -> 2 -> 1 -> null
C. 1 -> 2 -> 3 -> 4 -> 5 -> null
D. 1 -> 3 -> 5 -> 2 -> 4 -> null

Solution

  1. Step 1: Identify the reorder pattern

    The reorder pattern takes first node, last node, second node, second last node, and so on.
  2. Step 2: Apply pattern to given list

    Start with 1, then 5, then 2, then 4, then 3 remains in the middle.
  3. Final Answer:

    1 -> 5 -> 2 -> 4 -> 3 -> null -> Option A
  4. Quick Check:

    Alternate front and back nodes [OK]
Hint: Alternate nodes from front and back [OK]
Common Mistakes:
  • Reversing entire list instead of reordering
  • Not alternating nodes correctly
  • Leaving list unchanged
4. Consider this C# code snippet for reordering a linked list. What is the bug?
public void ReorderList(ListNode head) {
  if (head == null) return;
  ListNode slow = head, fast = head;
  while (fast != null && fast.next != null) {
    slow = slow.next;
    fast = fast.next.next;
  }
  ListNode second = ReverseList(slow);
  ListNode first = head;
  while (second != null) {
    ListNode temp1 = first.next;
    ListNode temp2 = second.next;
    first.next = second;
    second.next = temp1;
    first = temp1;
    second = temp2;
  }
}
medium
A. The ReverseList method is missing
B. The middle node is included in the reversed second half causing cycle
C. The fast pointer initialization is incorrect
D. The loop condition should be while (second.next != null)

Solution

  1. Step 1: Analyze slow pointer position after loop

    After the loop, slow points to the middle node, which is included in the reversed second half.
  2. Step 2: Understand consequence of including middle node

    Including the middle node causes the merged list to have a cycle or incorrect links because the middle node is connected twice.
  3. Final Answer:

    The middle node is included in the reversed second half causing cycle -> Option B
  4. Quick Check:

    Exclude middle node before reversing second half [OK]
Hint: Exclude middle node before reversing second half [OK]
Common Mistakes:
  • Not splitting list before reversing second half
  • Incorrect loop conditions
  • Assuming ReverseList is missing error
5. You have a linked list with nodes: 10 -> 20 -> 30 -> 40 -> 50 -> 60 -> null. After applying the reorder linked list algorithm, what is the correct final list?
hard
A. 10 -> 30 -> 50 -> 20 -> 40 -> 60 -> null
B. 60 -> 50 -> 40 -> 30 -> 20 -> 10 -> null
C. 10 -> 20 -> 30 -> 40 -> 50 -> 60 -> null
D. 10 -> 60 -> 20 -> 50 -> 30 -> 40 -> null

Solution

  1. Step 1: Identify the reorder pattern for even length list

    For even nodes, reorder alternates first and last nodes: 10, 60, 20, 50, 30, 40.
  2. Step 2: Apply the pattern to given list

    Start with 10, then 60, then 20, then 50, then 30, then 40, ending with null.
  3. Final Answer:

    10 -> 60 -> 20 -> 50 -> 30 -> 40 -> null -> Option D
  4. Quick Check:

    Alternate front and back nodes for even length [OK]
Hint: Alternate nodes from front and back for even length [OK]
Common Mistakes:
  • Reversing entire list instead of reordering
  • Not handling even length correctly
  • Leaving list unchanged
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard