Skip to content
Decoder

Middle of the List

Easy

Problem

Given the head of a non-empty linked list, return the middle node. If there are two middle nodes (an even count), return the second one. Aim for a single pass.

The tests show the list from the node you return onwards.

Example 1

Input
1
Output
2 -> 3 -> 4 -> 5 → 3 -> 4 -> 5

Example 2

Input
1
Output
2 -> 3 -> 4 -> 5 -> 6 → 4 -> 5 -> 6

Constraints

  • 1 <= number of nodes <= 100
  • 1 <= Node.val <= 100

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.