FastPrepMerge k Sorted Lists
Problems/Merge k Sorted Lists

Merge k Sorted Lists

ZS logoZS● HardNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report links the Merge k Sorted Lists task. The function signature, examples, and execution limits are the same as in a matching reviewed task of ours. Our version is about 95% the same as the reported question.

You are given an array lists containing k linked-list heads. Every linked list is sorted in ascending order.

Merge all of the linked lists into one ascending linked list and return its head.

Function

mergeKLists(lists: ListNode[]) → ListNode

Examples

Example 1

lists = [[1,4,5],[1,3,4],[2,6]]return = [1,1,2,3,4,4,5,6]
return
11234456

The linked lists are:

1 -> 4 -> 5
1 -> 3 -> 4
2 -> 6

Merging them produces the sorted linked list 1 -> 1 -> 2 -> 3 -> 4 -> 4 -> 5 -> 6.

Example 2

lists = []return = []
return
empty

Example 3

lists = [[]]return = []
return
empty

Constraints

  • k == lists.length
  • 0 <= k <= 10^4
  • 0 <= lists[i].length <= 500
  • -10^4 <= lists[i][j] <= 10^4
  • Each lists[i] is sorted in ascending order.
  • The sum of all lists[i].length values does not exceed 10^4.

More ZS Onsite Interview questions

  • Employees Whose Manager Left the CompanyONSITE INTERVIEW · Seen Sep 2026
  • Merge Two Sorted Linked ListsONSITE INTERVIEW · Seen Sep 2026
  • Fifth Highest Salary In A DepartmentONSITE INTERVIEW · Seen Sep 2026
  • Find Duplicate Email AddressesONSITE INTERVIEW · Seen Sep 2026
  • Top Salaries By DepartmentONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • LRU Cache with TTLAutodesk · ONSITE INTERVIEWAutodesk interview questions
  • Merge k Sorted ListsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Thread-Safe LRU Cache with TTLLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
  • Merge K Sorted ListsBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Merge K Sorted ListsSkydio · ONSITE INTERVIEWSkydio interview questions
  • Running Median of a Multilevel Linked List in Level OrderNutanix · ONSITE INTERVIEWNutanix interview questions
  • Greedy Person-Cake Matching DistanceSnowflake · PHONE SCREENSnowflake interview questions
  • LRU Cache with Expiring EntriesPaytm · PHONE SCREENPaytm interview questions
  • Merge K Sorted Linked ListsBharatPe · PHONE SCREEN
  • Merge k Sorted ListsOracle · PHONE SCREENOracle interview questions
All ZS interview questionsSee ZS hiring insights
Saved
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution {
    public ListNode mergeKLists(ListNode[] lists) {
        // write your code here
    }

}
Checking account…