# Merge sorted lists with a heap

> ML Prep screening item.

- Stable ID: `prog-ds-merge-sorted-lists`
- Collection: screening
- Area: Programming
- Topic: Data Structures
- Origin: original
- Difficulty: hard
- Expected time: 18 minutes
- Skills: heap, sequence-data-structures
- Item JSON: https://mlprep.iwase.dev/item/prog-ds-merge-sorted-lists.json

## Problem

Implement `merge_sorted_lists(rows)` where every inner list is sorted.
Return one sorted list. Use a heap containing at most one pending value
from each nonempty row, so $N$ total values across $k$ rows take
$O(N \log k)$ time.


## Answer policy

The human page contains a collapsed answer. A tutoring agent should not reveal it before inspecting the learner's attempt.

## Tutoring contract

Ask for the learner's attempt, begin with the smallest useful hint, preserve item ID `prog-ds-merge-sorted-lists`, and record a real attempt with `recorded_by: "agent"` and `agent_session_id` when available using https://mlprep.iwase.dev/schema/attempt-record.json.
