Reverse Linked List
Python data engineering interview problem. Difficulty: intermediate. Pattern: Linked Lists. About 14 minutes. Part of the Pro drill bank.
Reverse a singly linked list represented as a Python list of values. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.
A linked list stores a chain of values, but a reverse operation is often needed before sending the chain to another step. Return the values in the opposite order. The list form stands in for the linked nodes, so the first value becomes last and the last becomes first. Write reverse_list(values: list) -> list. [1, 2, 3, 4, 5] becomes [5, 4, 3, 2, 1]. The starter file already has the function name and harness print lines. Keep them and fill only the function body.
Requirements
- Reverse every value exactly once.
- Keep the returned values in reverse order.
- Return a list, not an iterator.
Constraints
- The input may be empty or contain one value.
- The function models a singly linked list and should not assume sorted values.
Examples
Input: reverse_list([1, 2, 3, 4, 5]) Output: [5, 4, 3, 2, 1] Head becomes the old tail.
Topics: lakebench, python, reverse, list api.
More Python interview questions · All interview problems · Learn data engineering
Reverse Linked List
Interview-style drill: Reverse a singly linked list represented as a Python list of values.
Implement `reverse_list(values: list) -> list` reversing the order of values (list API for a linked list). Example: `[1, 2, 3, 4, 5]` → `[5, 4, 3, 2, 1]`. Keep the harness.