Merge K Sorted Linked Lists Into One
Updated
Problem statement
lists holds the heads of k linked lists, and the values inside each list never decrease from front to back. Some lists, or the whole array, may be empty.
Relink all of their nodes into a single list whose values never decrease, keeping every repeated value, and return its head.
Function
mergeKLists(lists: ListNode[]) → ListNodeExamples
Example 1
lists = [[3,9],[-1,4,4,12],[7]]return = [-1,3,4,4,7,9,12]All seven values end up in one list in order: -1 from the second list, then 3, both 4s, 7, 9 and 12.
Example 2
lists = [[10],[1],[5]]return = [1,5,10]Each list holds one node. Joined in order they give 1, 5, 10, which is not the order the lists were given in.
Example 3
lists = [[-4,-4],[],[-4]]return = [-4,-4,-4]The empty list adds nothing. All three -4 nodes are kept.
Constraints
0 <= lists.length <= 300- Each list has at most
300nodes, and all lists together have at most3000. -10^4 <= Node.val <= 10^4, and within each list the values never decrease.
More Capital One Onsite Interview questions
- Digit-Coded Card ValidationONSITE INTERVIEW · Seen Nov 2026
- Sort ColorsONSITE INTERVIEW · Seen Oct 2026
- Virtual Card Transaction ValidatorONSITE INTERVIEW · Seen Oct 2026
- Banking System with Top ActivityONSITE INTERVIEW · Seen Sep 2026
- Transaction Event StoreONSITE INTERVIEW · Seen Jul 2026
- Shortest Path in an Unweighted GraphONSITE INTERVIEW · Seen Jul 2026
- Duplicate Transactions Within 60 SecondsONSITE INTERVIEW · Seen May 2026
- LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
- Cashback TrackerONSITE INTERVIEW · Seen Nov 2025
- Reverse a StringOA · ONSITE INTERVIEW · Seen Oct 2025
Similar questions at other companies
- Reverse Nodes in K-GroupAmazon · ONSITE INTERVIEW
- Merge K Sorted Linked ListsThe Walt Disney Company · OA · ONSITE INTERVIEWThe Walt Disney Company interview questions
- Merge K Sorted ListsBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Reverse Nodes in k-GroupMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Merge K Sorted ListsSkydio · ONSITE INTERVIEWSkydio interview questions
- Reverse a Linked List in Groups of KExpedia · ONSITE INTERVIEWExpedia interview questions
- Sorted Doubly Linked List to Balanced BST In PlaceSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Merge K Sorted Linked ListsBharatPe · PHONE SCREEN
- Reverse Nodes in K-GroupByteDance · PHONE SCREENByteDance interview questions
- Reverse a Linked ListCisco · PHONE SCREENCisco interview questions
Capital One interview experiences
- Capital One Experienced Engineer Power Day and OA: 6 Experiences
- Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
- Capital One TDP Agentic Round (AI Coding): 7 Experiences
- Capital One SWE Power Day, Level Not Reported: 6 Experiences
- Capital One TIP Intern OA and Power Day: 13 Experiences
- Capital One TDP Agentic Power Day: 25 Experiences (Part 1 of 2)