The empty stream
transcript
You merge three streams. One of them is empty. The code reads the first item. There is none. It fails.
Stream one has no events. Without a guard, the loop reads its first item. There is nothing to read. Add a guard instead.
Check the length first. Push a stream only if it has an item. Empty streams are skipped. The heap holds only real fronts. Every pop then has an item to return.
Time one comes from stream two. The two threes tie. Stream zero goes first. Then stream two. Order: two, zero, two.
A crash loses the whole merge. An empty list is a normal input in real logs. One length check prevents the failure. Add it before the first push.
Test an empty list first. Test a single list too. Test equal values across lists.
Check each stream first. Push only real items. Full breakdown in the lecture.