Mid
From PDF
Coding
C# Coding Interview
Merge k sorted linked lists into one sorted linked list?
Short answer: ListNode MergeKLists(ListNode[] lists) {
Example code
if (lists == null || lists.Length == 0) return null; PriorityQueue<ListNode, int> pq = new PriorityQueue<ListNode, int>();
foreach (var list in lists)
if (list != null) pq.Enqueue(list, list.val); ListNode dummy = new ListNode(0);
ListNode current = dummy; while (pq.Count > 0) { var node = pq.Dequeue();
current.next = node;
current = current.next;
if (node.next != null) pq.Enqueue(node.next, node.next.val); }
return dummy.next;
} Follow on: Explanation: Use a min-heap (priority queue) to always pick the smallest head node among k lists.
Real-world example (ShopNest)
In coding rounds, state complexity aloud, write a clear ShopNest-flavored example (orders, carts), then handle edge cases (empty list, null, overflow).
Say this in the interview
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png