Reverse a Singly Linked List
Updated
Problem statement
You are given head, the first node of a singly linked list. Reverse the list and return the first node of the reversed list.
After the reversal, the old last node is the new first node, every link points the other way, and the old first node is the new last node. If the list is empty, head is null and you return null.
Function
reverseList(head: ListNode) → ListNodeExamples
Example 1
head = [7,3,9,2]return = [2,9,3,7]Moved or new
The list is 7 -> 3 -> 9 -> 2. Read from the last node back to the first, the values are 2, 9, 3, 7, so the new head holds 2.
Example 2
head = [4,4,-1]return = [-1,4,4]Moved or new
Values may repeat. The last node holds -1, so it becomes the new head, followed by the two nodes that hold 4.
Example 3
head = [10]return = [10]A list with one node is the same when reversed.
Constraints
0 <= n <= 1000, wherenis the number of nodes.- Every node value is between
-10^5and10^5. - Values may repeat.
More Expedia Onsite Interview questions
- Scramble StringONSITE INTERVIEW · Seen Sep 2026
- Smallest Sufficient TeamONSITE INTERVIEW · Seen Sep 2026
- Check Anagram Pairs Index by IndexONSITE INTERVIEW · Seen Oct 2025
- Fresh Oranges Left After Rotting StopsONSITE INTERVIEW · Seen Oct 2025
- Longest Increasing SubsequenceONSITE INTERVIEW · Seen Oct 2025
- Lowest Common Ancestor with Repeated and Missing ValuesONSITE INTERVIEW · Seen Oct 2025
- Shortest Substring with Exactly K OnesONSITE INTERVIEW · Seen Oct 2025
- Middle Element of a Linked ListONSITE INTERVIEW · Seen Nov 2024
- Minimum in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Sep 2024
- Mirror Image Binary TreesONSITE INTERVIEW · Seen Sep 2024
Similar questions at other companies
- Reverse a Linked ListCisco · PHONE SCREENCisco interview questions
- Reverse a Linked ListApple · PHONE SCREENApple interview questions
- Reverse a Singly Linked ListChubb · PHONE SCREENChubb interview questions
- Reverse a Singly Linked ListMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Reverse a Singly Linked ListAdobe · PHONE SCREENAdobe interview questions
- Remove Linked List ElementsBloomberg LP · PHONE SCREENBloomberg LP 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
- Sorted Doubly Linked List to Balanced BST In PlaceSalesforce · ONSITE INTERVIEWSalesforce interview questions
Expedia interview experiences
- Expedia Intern Final Round in 2021: 28 Experiences (Part 4 of 6)
- Expedia Intern Finals Before 2020: 14 Experiences (Part 6 of 6)
- Expedia Intern Final Round in 2020: 24 Experiences (Part 5 of 6)
- Expedia Intern Final Round in 2022: 15 Experiences (Part 3 of 6)
- Expedia Intern Final Round in 2023: 17 Experiences (Part 2 of 6)
- Expedia SWE Intern Final Round: 126 Experiences (Part 1 of 6)