Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Split a list into two halves

Split a singly linked list into two halves using the fast/slow pointer method.

Python practice16 minLinked ListsIntermediateLast updated March 27, 2026

Problem statement

Given a singly linked list represented by a Python list of values, split it into two halves and return a tuple of two Python lists representing the first and second halves. If the list has an odd number of nodes, the extra node should go into the first (front) half. You must construct a linked list and perform the split by manipulating next pointers (simulate in-place split). Use the fast/slow pointer approach to find the midpoint. Return (first_half_values, second_half_values).

Task

Given a list represented as a Python list, split it into two halves (as Python lists) by constructing a linked list and splitting in-place at the midpoint.

Examples

Even length split

Input

[1, 2, 3, 4]

Output

([1, 2], [3, 4])

Four nodes split evenly into two lists of two nodes each.

Input format

A single Python list representing the linked list values.

Output format

A tuple of two Python lists: (first_half_values, second_half_values).

Constraints

- The input list can be empty. Use O(n) time and O(1) extra linked-list pointers for splitting.

Samples

Sample 1

Input

[1, 2, 3, 4, 5]

Output

([1, 2, 3], [4, 5])

Odd length: first half gets the extra element.