Sort a Linked List
Updated
Problem statement
You are given the head of a singly linked list. Sort the list so that its values are in increasing order, and return the head of the sorted list.
Values may repeat; every node stays in the list, so equal values appear next to each other in the result.
Function
sortLinkedList(head: ListNode) → ListNodeExamples
Example 1
head = [7,-3,12,0,5]return = [-3,0,5,7,12]Moved or new
The values in increasing order are -3, 0, 5, 7, 12, so the sorted list is [-3,0,5,7,12].
Example 2
head = [9,9,2,9]return = [2,9,9,9]Moved or new
Equal values all stay in the list: [2,9,9,9].
Example 3
head = [1]return = [1]A single node is already sorted.
Constraints
- The list has between
1and2000nodes. -10^5 <= node.val <= 10^5
More Adobe Phone Screen questions
- Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
- All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
- Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
- Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
- Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
- Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
- Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
- Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026
Similar questions at other companies
- Merge K Sorted Linked ListsBharatPe · PHONE SCREEN
- Sort a Linked List in Descending OrderMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Locate Vehicles with Square QueriesApplied Intuition · PHONE SCREENApplied Intuition interview questions
- Merge Timestamped Record ListsNuro · PHONE SCREENNuro interview questions
- Nested Set Structural EquivalencePinterest · PHONE SCREEN · ONSITE INTERVIEWPinterest interview questions
- Flatten a Multilevel Doubly Linked ListBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Filter Linked-List Nodes and Keep Top KGoogle · PHONE SCREENGoogle interview questions
- Swap Adjacent Linked List NodesNutanix · PHONE SCREENNutanix interview questions
- Build a Sorted Circular Singly Linked ListAnduril · PHONE SCREENAnduril interview questions
- Reverse a Linked ListCisco · PHONE SCREENCisco interview questions
Interview reports that mention this question
Adobe interview experiences
- Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
- Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
- Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
- Adobe New Grad MTS Interview Questions: 7 Experiences
- Adobe ML/Research Intern Interviews: 12 Experiences (Part 4 of 4)