Back to problems

Implement lazy unique-merge generator for sorted streams

Algorithm · Citadel · Hard

Implement merge_unique(a, b), a Python function that accepts two nondecreasing iterables and returns a list containing each distinct value from either input in sorted order. Repeated values that appear multiple times in one input, or in both inputs, must be emitted only once. The function should consume the inputs lazily: advance each iterator only when necessary to determine the next output value, and never materialize an entire stream into a list or other full copy. This…

Checking your access…