Reverse a Linked List
Updated
Problem statement
You are given the head of a singly linked list. Reverse the list and return the head of the reversed list.
The list is shown in the examples as the values of its nodes from head to tail.
Function
reverseList(head: ListNode) → ListNodeExamples
Example 1
head = [1,2,3,4]return = [4,3,2,1]Moved or new
The last node 4 becomes the new head, and every link now points the other way: 4 -> 3 -> 2 -> 1.
Example 2
head = [7]return = [7]A list with one node is the same when reversed.
Example 3
head = []return = []An empty list stays empty, so the answer is an empty list.
Constraints
- The number of nodes in the list is in the range
[0, 5000]. -5000 <= Node.val <= 5000
More Cisco interview questions
- Check if a String Is a PalindromePHONE SCREEN · Seen Nov 2026
- Find Unique ElementsPHONE SCREEN · Seen Nov 2026
- First Letter to Appear TwicePHONE SCREEN · Seen Nov 2026
- Middle of a Linked ListPHONE SCREEN · Seen Nov 2026
- Reverse a StringPHONE SCREEN · Seen Nov 2026
- Valid ParenthesesPHONE SCREEN · Seen Nov 2026
- K-Step Bit Flip with RetentionPHONE SCREEN · Seen Nov 2026
- Longest Non-Repeating SubstringPHONE SCREEN · Seen Jul 2026
- Todo Task Manager OperationsONSITE INTERVIEW · Seen Oct 2026
- Find the Duplicate Number Without Modifying the ArrayONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Reverse a Linked ListApple · PHONE SCREENApple 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
- Merge K Sorted Linked ListsBharatPe · PHONE SCREEN
- Reverse Nodes in K-GroupByteDance · PHONE SCREENByteDance interview questions
- Reverse a Singly Linked ListMicrosoft · ONSITE INTERVIEWMicrosoft interview questions