Reverse Linked List
Updated
Problem statement
Reverse a singly linked list. You receive its first node, head, and return the node that heads the reversed list.
Keep the same nodes and turn every link around: wherever node A pointed to node B, B now points to A. The old tail is now the first node and the old head is now the last. Values may repeat. An empty list (head is null) gives an empty list.
Function
reverseList(head: ListNode) → ListNodeExamples
Example 1
head = [3,8,1,6]return = [6,1,8,3]Moved or new
Node 6 was last and now comes first. Each link points back to the node that used to precede it, so the values read 6, 1, 8, 3.
Example 2
head = [10,20]return = [20,10]Moved or new
The two nodes swap places: 20 now links to 10, and 10 links to nothing.
Example 3
head = [-2,5,-2,9]return = [9,-2,5,-2]Moved or new
Values may be negative and may repeat. Both nodes holding -2 stay in the list, and following the reversed links reads 9, -2, 5, -2.
Constraints
0 <= list length <= 5000-5000 <= value of each node <= 5000
More Autodesk interview questions
- Non-Repeating CharacterONSITE INTERVIEW · Seen Nov 2026
- Remove Trailing ZerosONSITE INTERVIEW · Seen Nov 2026
- LRU Cache with TTLONSITE INTERVIEW · Seen Oct 2026
- Deep Merge with a Conflict ResolverONSITE INTERVIEW · Seen Mar 2026
- Diagonal Bounce TraversalOA · Seen Oct 2026
- Interleave Array HalvesOA · Seen Oct 2026
- Latest Arrival to Catch a BusOA · Seen Oct 2026
- Find Top Two TeamsOA · Seen Sep 2026
- In-Memory Database with TTLOA · Seen Mar 2026
Similar questions at other companies
- Reverse a Singly Linked ListMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Reverse a Singly Linked ListBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Merge Two Sorted ListsWhatNot · ONSITE INTERVIEWWhatNot interview questions
- Remove Linked List Nodes with a Given ValueExpedia · ONSITE INTERVIEWExpedia interview questions
- Reverse a Linked ListBank of America · ONSITE INTERVIEWBank of America interview questions
- Sorted Doubly Linked List to Balanced BST In PlaceSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Reverse Nodes in K-GroupAmazon · ONSITE INTERVIEW
- Merge K Sorted Linked ListsThe Walt Disney Company · OA · ONSITE INTERVIEWThe Walt Disney Company interview questions
- Merge K Sorted ListsSkydio · ONSITE INTERVIEWSkydio interview questions
- Merge K Sorted Linked Lists Into OneCapital One · ONSITE INTERVIEWCapital One interview questions