The core logic clicked pretty fast since it's basically a merge step from merge sort, but the deduplication part is where I had to slow down.
Clarify the iterator interface and constraints, then propose a two-pointer merge that advances the iterator with the smaller current value, skipping duplicates and handling equal values by advancing both. Discuss edge cases, complexity, and potential optimizations like lazy evaluation and peekable iterators.
Pro tip: Mention that this is essentially a merge step of merge sort with deduplication, and highlight that the iterator should be lazy to handle infinite streams and avoid unnecessary memory usage.
Ask about the iterator interface (e.g., hasNext, next, peek), whether inputs are truly duplicate-free, and if the output should be lazy. Confirm that inputs are sorted ascending.
Maintain current values from both iterators. At each step, compare them: if one is smaller, yield it and advance that iterator; if equal, yield once and advance both. Skip any duplicates that might appear (though inputs are duplicate-free, the union might still need to handle equal values).
Consider when one or both iterators are exhausted. Ensure the algorithm correctly yields remaining elements from the non-exhausted iterator. Handle empty inputs gracefully.
State time complexity O(n+m) and space O(1) for the merge logic (excluding input storage). Discuss lazy evaluation to support infinite streams and avoid materializing the entire output.
Write pseudocode or actual code for the iterator, then walk through a few examples (e.g., [1,3,5] and [2,3,6]) to verify correctness. Mention unit tests for edge cases.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.