KatInterview

Reverse a Sequence of Node Values

Linked ListsAuto-graded · 22 test cases
EasyAuto-gradedLinked Listslinked-listsarrayspointers

Last updated

Tests the ability to reverse a sequential list of numbers efficiently, mimicking linked list reversal operations.

Given a list of integers values representing the sequential elements of a data structure (such as node values in a singly linked list), return a new list containing all elements in reverse order.

An empty input list should return an empty list.

Constraints:

  • 0 <= len(values) <= 10^4
  • -10^9 <= values[i] <= 10^9

Examples

Example 1

Input: reverse_list([1, 2, 3, 4, 5])

Output: [5, 4, 3, 2, 1]

Example 2

Input: reverse_list([])

Output: []

Hints

Hint 1

Think about reversing the order of elements either sequentially or using modern array manipulation techniques.

Hint 2

Make sure to handle edge cases like an empty input list or single-element inputs.

Hint 3

For a standard Python list, a single slicing operation can reverse all elements efficiently.