Reverse a Singly Linked List
Updated
Problem statement
Given the head of a singly linked list, reverse the order of its nodes and return the head of the reversed list.
For this practice, each node contains an integer value and a next pointer. An empty list is represented by null and reverses to an empty list. The input and output examples use arrays to display list values in traversal order.
Function
reverseList(head: ListNode) → ListNodeExamples
Example 1
head = [1,2,3,4,5]return = [5,4,3,2,1]Moved or new
The tail node becomes the new head, followed by the previous nodes in reverse order.
Example 2
head = []return = []There are no nodes to reverse, so the result is empty.
Example 3
head = [7,7,-2]return = [-2,7,7]Moved or new
Repeated values remain separate nodes; the value order becomes -2 -> 7 -> 7.
Constraints
- The list contains
0to100nodes. -10^4 <= node.val <= 10^4.- Return the nodes in exact reverse traversal order, preserving every value and occurrence.
More NVIDIA Phone Screen questions
- Network Layer Execution OrderPHONE SCREEN · Seen Nov 2026
- Paged KV Cache AccessPHONE SCREEN · Seen Nov 2026
- Sliding Window Attention over a KV CachePHONE SCREEN · Seen Nov 2026
- Summarize Server Healthcheck LogsPHONE SCREEN · Seen Oct 2026
- Hash Partition OffsetsPHONE SCREEN · Seen Oct 2026
- Filter Paginated Medical RecordsPHONE SCREEN · Seen Oct 2026
- Least Frequently Used CachePHONE SCREEN · Seen Oct 2026
- Parallel String Counts with a Custom Hash TablePHONE SCREEN · Seen Oct 2026
- Simulate a Reference-Counted Smart PointerPHONE SCREEN · Seen Aug 2026
- Streaming Top-K Frequent ElementsPHONE SCREEN · Seen Aug 2026
Similar questions at other companies
- Reverse Linked ListByteDance · PHONE SCREEN · ONSITE INTERVIEWByteDance interview questions
- Merge Two Sorted ListsLinkedIn · PHONE SCREENLinkedIn interview questions
- Middle of a Linked ListCisco · PHONE SCREENCisco interview questions
- Reverse a Linked ListApple · PHONE SCREENApple interview questions
- Merge Two Sorted ListsIBM · PHONE SCREENIBM interview questions
- Reverse a Singly Linked ListChubb · PHONE SCREENChubb interview questions
- Remove All Repeated Values from a Linked ListArista Networks · PHONE SCREENArista Networks interview questions
- Detect a Cycle in a Linked ListSalesforce · PHONE SCREENSalesforce interview questions
- Find the Intersection Node of Two Linked ListsVisa · PHONE SCREENVisa interview questions
- Reverse a Linked ListMygate · PHONE SCREENMygate interview questions