Middle of Linked List

Python data engineering interview problem. Difficulty: intermediate. Pattern: Linked Lists. About 14 minutes. Part of the Pro drill bank.

Return the middle node's value (second middle if even length). Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.

When a list is streamed, you may need its middle value without first counting every node. A fast pointer can move twice as quickly as a slow pointer. Return the middle value. If the length is even, the task says to return the second of the two middle positions. Write middle_node(values: list). [1, 2, 3, 4, 5] returns 3; an even list [1, 2, 3, 4, 5, 6] should return 4. The starter file already has the function name and harness print lines. Keep them and fill only the function body.

Requirements

  • Return a value, not an index.
  • Choose the second middle for even lengths.
  • Do not reorder the input.

Constraints

  • Values are represented as a Python list for a linked-list exercise.
  • An empty list needs a defined empty result such as None.

Examples

Input: middle_node([1, 2, 3, 4, 5]) Output: 3 Odd length middle.

Topics: lakebench, python, middle, two pointers.

More Python interview questions · All interview problems · Learn data engineering

intermediate

Middle of Linked List

Interview-style drill: Return the middle node's value (second middle if even length).

Implement `middle_node(values: list)` returning the middle value of the list API linked list. For even length, return the second middle. Example: `[1, 2, 3, 4, 5]` → `3`; `[1, 2, 3, 4, 5, 6]` → `4`. Keep the harness.