InferenceAI

Enter at least two characters to search.

Start free

Middle Node

easyLinked Lists15 min10 XP

Return the part of the list starting at its middle node. If there are two middle nodes, start at the second one.

Linked lists are given and returned as Python lists of node values, from head to tail. Think in terms of nodes and pointers; the list format just makes the tests readable.

Examples

EXAMPLE WALKTHROUGHodd length

A guided view of the published example, not a trace of your code.

INPUT[[1,2,3,4,5]]
TASKmiddle_node()
EXPECTED OUTPUT[3,4,5]

Start with the input values shown in this example.

Example 1 of 3

Input: values = [1,2,3,4,5]

Output: [3,4,5]

Explanation: odd length

Input: values = [1,2,3,4,5,6]

Output: [4,5,6]

Explanation: even length

Input: values = [1]

Output: [1]

Explanation: single

Hint 1

Slow moves one step and fast moves two; when fast reaches the end, slow is in the middle.

Topics

DSALinked ListsPython