Reverse a Linked List
Updated
Problem statement
Given the head of an acyclic singly linked list, reverse all of its next pointers and return the new head. Reuse the original data nodes. An empty list returns null.
Input and output lists are shown as arrays of node values.
Function
reverseList(head: ListNode) → ListNodeExamples
Example 1
head = [1,2,3,4]return = [4,3,2,1]Moved or new
The original final node becomes the new head.
Example 2
head = []return = []Reversing an empty list still produces null.
Constraints
- The list contains between
0and10000nodes. -10^9 <= node.val <= 10^9.
More Apple Phone Screen questions
- Topological OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Merge IntervalsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Subarray Product Less Than KPHONE SCREEN · Seen Nov 2026
- Evaluate DivisionPHONE SCREEN · Seen Nov 2026
- Validate a BST with a Custom ComparisonPHONE SCREEN · Seen Nov 2026
- Design a Food Rating SystemPHONE SCREEN · Seen Oct 2026
- Days Until Poisoned Plants StabilizePHONE SCREEN · Seen Oct 2026
- Capture Surrounded Regions with Union-FindPHONE SCREEN · Seen Oct 2026
- Maintain a Consistent-Hashing RingPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- Merge Two Sorted ListsLinkedIn · PHONE SCREENLinkedIn interview questions
- Reverse a Linked ListCisco · PHONE SCREENCisco interview questions
- Reverse a Singly Linked ListChubb · PHONE SCREENChubb interview questions
- Reverse a Singly Linked ListAdobe · PHONE SCREENAdobe interview questions
- Remove Linked List ElementsBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Reverse a Singly Linked ListExpedia · PHONE SCREEN · ONSITE INTERVIEWExpedia interview questions
- Merge Two Sorted Linked ListsNutanix · PHONE SCREENNutanix interview questions
- Reverse a Singly Linked ListSuperhuman · PHONE SCREENSuperhuman interview questions
- Convert a Sorted Linked List to a Balanced BSTMeta · PHONE SCREENMeta interview questions
- Merge K Sorted Linked ListsBharatPe · PHONE SCREEN