Skip to interview prep
Apexed

16. Middle of a Linked List

EasyLinked lists

Return the middle node of a linked list (as a list from that node onward). With two middle nodes, return the second.

A linked list is passed as ListNode objects with val and next. The tests write lists as arrays.

Example 1

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

Example 2

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

Constraints

  • 1 ≤ nodes ≤ 100

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 3 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Middle of a Linked List — coding interview practice — Apexed