Reverse the Order of a Linked List
Updated
Problem statement
You are given head, the first node of a singly linked list. Each node holds an integer val and a link next to the following node; the last node links to nothing. The list may be empty, in which case head is null.
Reverse the list so the nodes come in the opposite order, and return the head of the reversed list. The old last node becomes the new head.
Lists are written as their values from head to tail, for example [12,-5,30,7].
Function
reverseNodeOrder(head: ListNode) → ListNodeExamples
Example 1
head = [12,-5,30,7]return = [7,30,-5,12]Moved or new
The nodes are 12 → -5 → 30 → 7. After reversing, the last node (7) is the new head and every arrow points the other way: 7 → 30 → -5 → 12.
Example 2
head = [-4,0,-4,9]return = [9,-4,0,-4]Moved or new
Repeated values are separate nodes and both stay. Read from the end: 9, -4, 0, -4.
Example 3
head = [42]return = [42]A list with one node is the same list when reversed.
Constraints
0 <= number of nodes <= 5000-105 <= node.val <= 105
More DocuSign Onsite Interview questions
- Count Binary SubstringsONSITE INTERVIEW · Seen Sep 2026
- Two Positions That Add Up to a TargetPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Compress Consecutive Integer RangesONSITE INTERVIEW · Seen Aug 2026
- JSON Schema Object ValidatorONSITE INTERVIEW · Seen Aug 2026
- Most Transactions Kept Without Going NegativeONSITE INTERVIEW · Seen May 2025
- Three-Part Splits With a Light MiddleONSITE INTERVIEW · Seen May 2025
- Combine Two Sorted Lists Into OneONSITE INTERVIEW · Seen Apr 2022
- Exact Palindrome CheckPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2022
- Paired Words That Share a SubstringONSITE INTERVIEW · Seen Apr 2022
- Reverse the Characters of a TextPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2022
Similar questions at other companies
- Detect a Loop in a Linked ListEPAM · ONSITE INTERVIEWEPAM interview questions
- Delete a Doubly Linked List Node at a PositionQualys · ONSITE INTERVIEWQualys interview questions
- Insert After a Linked-List NodeAMD · ONSITE INTERVIEWAMD interview questions
- Reverse a Singly Linked ListGoogle · ONSITE INTERVIEWGoogle interview questions
- Process Singly Linked List OperationsSEDEMAC · ONSITE INTERVIEW
- Merge Two Sorted Linked ListsZS · ONSITE INTERVIEWZS interview questions
- Middle Node Of A Linked ListNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
- Build and Check a Palindrome Linked ListOmnissa · ONSITE INTERVIEWOmnissa interview questions
- Reverse a Singly Linked ListGEP · ONSITE INTERVIEW
- Merge Two Sorted Linked ListsApple · ONSITE INTERVIEWApple interview questions