My first instinct was just a standard k-way merge with a min-heap and I started coding that up before fully reading the tie-breaking part.
Use a min-heap (priority queue) to efficiently merge the k sorted lists by always extracting the smallest key. For duplicate keys, prioritize the node from the higher-indexed list by comparing list indices when keys are equal. Then analyze time and space complexity, noting the heap size is at most k.
Pro tip: Mention that if the lists are very large and k is small, a heap is optimal, but if k is huge, a divide-and-conquer merge might be better; also clarify how you handle duplicate keys to ensure the higher-indexed list wins.
Confirm that lists are sorted by key, keys may be duplicated, and higher-indexed list wins on ties. Discuss edge cases like empty lists, k=0, or all lists empty.
Select a min-heap (priority queue) to store the current head of each list. The heap comparator should order by key, and for equal keys, by list index descending (so higher index is extracted first).
Insert the head of each non-empty list into the heap. Repeatedly extract the minimum node, append it to the result list, and if that node has a next, insert the next node into the heap.
When extracting, if multiple nodes have the same key, the heap comparator ensures the one from the higher-indexed list is extracted first. This automatically enforces the 'higher-indexed list wins' rule.
Time complexity: O(N log k) where N is total number of nodes and k is number of lists. Space complexity: O(k) for the heap (plus O(N) for the output list).
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.