Skip to main content
CodeOath
← All problems

Problem

Middle of the Linked List

Easy
  • linked-list
  • two-pointers

Find the node in the middle of the singly linked list head and return it. When the list has an even number of nodes, two of them share the middle, and the answer is the later of the two.

Lists in this problem are written as a plain array of values, in order. A returned node is shown as the list that starts at it, so the output includes every node after the middle one.

Example 1
Input
head = [2, 4, 6, 8, 10]
Output
[6, 8, 10]
Explanation

five nodes put the middle at the third one, 6. The list from there on is 6, 8, 10.

Example 2
Input
head = [3, 6, 9, 12]
Output
[9, 12]
Explanation

with four nodes the centre pair is 6 and 9, and the later one, 9, is the answer.

Constraints:

  • the list has at least one node

Tab indents. Press Esc, then Tab to leave the editor.

Run your code to see every test here. Nothing is submitted or recorded.