#876

Middle of the Linked List

EasyTwo PointersHas vizLinked ListTwo Pointers
Related studio

Problem

Given the head of a singly linked list, return the middle node of the linked list.

If there are two middle nodes, return the second middle node.

Example 1

Input: head = [1,2,3,4,5]

Output: [3,4,5]

Middle node is 3.

Example 2

Input: head = [1,2,3,4,5,6]

Output: [4,5,6]

Two middles 3 and 4 — return the second.

Constraints

  • The number of nodes in the list is in the range [1, 100].
  • 1 <= Node.val <= 100
Loading visualization…

Explanation

Middle of the Linked List is a Easy interview problem tagged [Linked List, Two Pointers]. The winning approach is typically **Two Pointers**.

Intuition

Each pointer only moves forward/backward once, guaranteeing O(n) after any required sort.

Approach

Place two indices and move them based on a comparison or invariant (sorted order, palindrome symmetry, partition).

  1. Establish the invariant (e.g., array sorted).
  2. Initialize L and R.
  3. Move the pointer that improves the condition.
  4. Handle duplicates carefully if uniqueness is required.

Solution

Pattern-level skeleton only — not this problem’s exact answer. Adapt it to the statement.

Pattern templateTwo Pointers

Edge cases

  • •Empty or single-element input
  • •Duplicates and ties
  • •Maximum constraints / overflow
  • •Disconnected or unreachable states (for graphs)

Complexity

Time: O(n)

Space: O(1)

Before coding, restate the problem, name the pattern (Two Pointers), and write the invariant or DP state in one sentence.

Learn the topic

Got it?

Mark #876 Middle of the Linked List as understood when the pattern clicks.