Given a list of lists lists, merge them round-robin: take the first element of each list in order, then the second element of each list, and so on. Lists that have run out are skipped, and the process continues until every element has been taken.
Examples
Input: lists = [[1, 2, 3], [4], [5, 6]]
Output: [1, 4, 5, 2, 6, 3]
Explanation: round 1 takes 1, 4, 5; round 2 takes 2, 6 (the second list is empty); round 3 takes 3.
Input: lists = [[], [1]]
Output: [1]
Constraints
0 <= len(lists) <= 10**5, total number of elements<= 10**5- Return a new list; do not modify the inputs.
- Target: O(total elements + number of lists * longest list) time.
Goals
- Interleave any number of lists, not just two
- Skip lists that are already exhausted
- Handle empty inner lists and an empty outer list