QuizzesLinked Lists
intermediate
dsa

Linked Lists

Pointers, cycle detection, reversal, and the fast/slow pointer technique — the core linked list patterns.

25 minutes 10 questions Pass at 70%
Time Limit
25 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

10 questions on Linked Lists. Work through them here, then start the quiz to answer them and see your score.

  1. 1.What is the time complexity of inserting a node at the head of a singly linked list?

    • AO(1)
    • BO(n)
    • CO(n²)
    • DO(log n)
  2. 2.Floyd's cycle detection (fast/slow pointers) detects a cycle in O(n) time and how much extra space?

    • AO(n) space for the recursion stack
    • BO(1) — only two pointer variables needed
    • CO(n) — needs a HashSet of visited nodes
    • DO(log n) space
  3. 3.How do you find the middle node of a linked list in a single pass?

    • ASort the linked list first
    • BConvert to array and return arr[n/2]
    • CTraverse once to count n, traverse again to position n/2
    • DUse fast and slow pointers — when fast reaches the end, slow is at the middle
  4. 4.What does this function do?

    public ListNode reverse(ListNode head) {
        ListNode prev = null, curr = head;
        while (curr != null) {
            ListNode next = curr.next;
            curr.next = prev;
            prev = curr;
            curr = next;
        }
        return prev;
    }
    • AFinds the middle node
    • BSorts the linked list
    • CDeletes the last node
    • DReverses the linked list in-place, returning the new head
  5. 5.What is a dummy head (sentinel) node and why is it used?

    • AA node that marks the end of the list
    • BA placeholder node before the real head that eliminates special cases when the head itself may change
    • CA node that stores the list's length
    • DThe last node in a circular linked list
  6. 6.What is the time complexity of merging two sorted linked lists?

    • AO(n log n)
    • BO(n + m)
    • CO(n × m)
    • DO(1)
  7. 7.After Floyd's meeting point, how do you find the exact start of the cycle?

    • AThe meeting point itself is the cycle start
    • BThe slow pointer is always at the cycle start when fast first catches it
    • CReset one pointer to head; advance both one step at a time — they meet at the cycle start
    • DCount the cycle length, then position a pointer k steps from the head
  8. 8.What does this return for list 1→2→3→4→5 with n = 2?

    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode dummy = new ListNode(0);
        dummy.next = head;
        ListNode fast = dummy, slow = dummy;
        for (int i = 0; i <= n; i++) fast = fast.next;
        while (fast != null) {
            fast = fast.next;
            slow = slow.next;
        }
        slow.next = slow.next.next;
        return dummy.next;
    }
    • A1→2→3→4
    • B1→3→4→5
    • C1→2→4→5
    • D1→2→3→5
  9. 9.What is the space complexity of reversing a linked list recursively vs iteratively?

    • ARecursive: O(log n); Iterative: O(n)
    • BBoth O(1)
    • CRecursive: O(n) call stack; Iterative: O(1)
    • DBoth O(n)
  10. 10.Palindrome Linked List in O(n) time and O(1) space — what is the approach?

    • AFind middle (fast/slow pointers), reverse second half in-place, compare with first half
    • BConvert to array, use two pointers
    • CUse a stack to store all values, then compare
    • DCount occurrences of each value