Even length split
Input
[1, 2, 3, 4]
Output
([1, 2], [3, 4])
Four nodes split evenly into two lists of two nodes each.
Full lesson preview
Split a singly linked list into two halves using the fast/slow pointer method.
Problem statement
Task
Examples
Input
[1, 2, 3, 4]
Output
([1, 2], [3, 4])
Four nodes split evenly into two lists of two nodes each.
Input format
Output format
Constraints
Samples
Input
[1, 2, 3, 4, 5]
Output
([1, 2, 3], [4, 5])
Odd length: first half gets the extra element.