← DiffPush

Find mid of LL

Standard Bar Linked List · Medium Problems of LL O(N) · O(1)

Halving the Inspection Line at the Right Checkpoint

A plant inspection line is a one-way chain of stations, and the QA lead wants a second team dispatched from the exact midpoint to halve the work. The line has no length posted, and with an even station count the tie goes to the later of the two central stations. Send back the remaining chain that starts at that station.

Input: An array head of node values representing the linked list.

Output: The values of the list starting at the middle node; with two middles, start at the second one.

Constraints

Examples

Example 1

Input: {"head":[1,2,3,4,5]}
Output: [3,4,5]
Five stations split at the third — the sole middle node.

Example 2

Input: {"head":[1,2,3,4,5,6]}
Output: [4,5,6]
Six stations have two middles (3 and 4); the later one wins the split.

Solve this in your browser →

Also on LeetCode ↗