Reverse a singly linked list by updating its next pointers

Quick Overview

Reverse a singly linked list by updating its next pointers and return its serialized values. Preserve access to the remaining nodes, handle empty and repeated-value inputs, and distinguish reversal space from adapter storage.

Reverse a singly linked list by updating its next pointers

Company: ByteDance

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Reverse a singly linked list so its nodes appear in the opposite order. Change the nodes' `next` links and return the values encountered from the new head. The callable receives and returns a value-list serialization for portability. Inside the implementation, build the corresponding singly linked nodes and reverse their links. Replacing the task with array slicing or reversed-value copying does not satisfy the pointer-manipulation requirement. ### Function Signature ```python def reverse_linked_values(values: list[int]) -> list[int]: ``` ### Rules - The input list represents nodes from head to tail and contains no cycle. - Preserve every node value, including duplicates. - The returned list serializes the nodes from the new head to the new tail. - Empty input returns an empty list. - Serialization is an exercise adapter around the linked-list operation. ### Constraints These are exercise bounds. - `0 <= len(values) <= 100000`. - `-1000000000 <= values[i] <= 1000000000`. ### Examples ```text Input: values = [1, 2, 3, 4] Output: [4, 3, 2, 1] ``` The old tail becomes the head and the old head's next pointer becomes null. ```text Input: values = [5, 5, 2] Output: [2, 5, 5] ``` Equal values remain separate nodes and are preserved.

Overview: Reverse a singly linked list by updating its next pointers and return its serialized values. Preserve access to the remaining nodes, handle empty and repeated-value inputs, and distinguish reversal space from adapter storage.

ByteDance logo
ByteDance
Nov 26, 2026
mediumSoftware EngineerTechnical ScreenCoding & Algorithms
0
0

Reverse a singly linked list so its nodes appear in the opposite order. Change the nodes' next links and return the values encountered from the new head.

The callable receives and returns a value-list serialization for portability. Inside the implementation, build the corresponding singly linked nodes and reverse their links. Replacing the task with array slicing or reversed-value copying does not satisfy the pointer-manipulation requirement.

Function Signature

def reverse_linked_values(values: list[int]) -> list[int]:

Rules

  • The input list represents nodes from head to tail and contains no cycle.
  • Preserve every node value, including duplicates.
  • The returned list serializes the nodes from the new head to the new tail.
  • Empty input returns an empty list.
  • Serialization is an exercise adapter around the linked-list operation.

Constraints

These are exercise bounds.

  • 0 <= len(values) <= 100000 .
  • -1000000000 <= values[i] <= 1000000000 .

Examples

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

The old tail becomes the head and the old head's next pointer becomes null.

Input: values = [5, 5, 2]
Output: [2, 5, 5]

Equal values remain separate nodes and are preserved.