FastPrepMerge K Sorted Linked Lists
Problems/Merge K Sorted Linked Lists

Merge K Sorted Linked Lists

BharatPe logoBharatPe● HardFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a BharatPe full-time phone screen. The report names Merge K Sorted Linked Lists with no interface or examples. We kept the standard linked-list task and added limits so the thin report can be run. Our version is about 99% the same as the reported question.

You are given an array lists of k singly linked lists. Every linked list is sorted in nondecreasing order.

Merge all nodes into one linked list sorted in nondecreasing order and return its head. You may relink the existing nodes.

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

Taking the smallest current head repeatedly produces the combined sorted order.

Example 2

lists = []return = []
return
empty

There are no nodes to merge.

Example 3

lists = [[],[-2,0,7],[3]]return = [-2,0,3,7]
return
-2037

Empty lists contribute no nodes; the remaining two lists merge in sorted order.

Constraints

  • 0 <= k <= 100
  • The total number of nodes across all lists is at most 5000.
  • -10^9 <= node.val <= 10^9
  • Every input list is sorted in nondecreasing order.

More BharatPe Phone Screen questions

  • Wallet Balance on a Selected DayPHONE SCREEN · Seen Sep 2026

Similar questions at other companies

  • Merge K Sorted ListsBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Merge Timestamped Record ListsNuro · PHONE SCREENNuro interview questions
  • Sort a Linked ListAdobe · PHONE SCREENAdobe interview questions
  • Merge K Sorted ListsSkydio · ONSITE INTERVIEWSkydio interview questions
  • Sort a Linked List in Descending OrderMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • IPOThe D.E. Shaw Group · PHONE SCREENThe D.E. Shaw Group interview questions
  • Greedy Person-Cake Matching DistanceSnowflake · PHONE SCREENSnowflake interview questions
  • Find Median from Data StreamSusquehanna International Group (SIG) · PHONE SCREENSusquehanna International Group (SIG) interview questions
  • Median Across Sorted ArraysGoogle · PHONE SCREENGoogle interview questions
  • Document Indexer Scheduling MetricsGlean · PHONE SCREENGlean interview questions
See BharatPe 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…