easyLinked ListPure DSA~15 min
Playlist Middle Track
A music app shows a 'jump to middle' control on long playlists. The playlist is a singly linked list of tracks and the app does not store its length. Return the middle track in a single pass — for an even number of tracks, return the second of the two middle tracks.
Problem
Given the head of a singly linked list, return the middle node. If there are two middle nodes (even length), return the second one.
Input
The head of a singly linked list with n nodes (1 ≤ n ≤ 10^5).
Output
The middle node (reference to the node, value shown in examples).
Constraints
- 1 ≤ n ≤ 100,000
- Length is not known in advance
- Single pass preferred (no length pre-count)
Examples
Example 1
Input
list = 10 → 20 → 30 → 40 → 50
Output
30
Odd length 5; the middle (index 2) holds 30.
Example 2
Input
list = 10 → 20 → 30 → 40
Output
30
Even length 4; the two middles are 20 and 30 — return the second, 30.