Part one is basically just a counter times k, took maybe two minutes.
Start by clarifying the requirements: for a single k, next() should return k, 2k, 3k, ... in order. For multiple base integers, use a min-heap to merge the sequences, tracking the current multiple for each base and deduplicating when values coincide. Discuss time and space complexity, and consider edge cases like zero or negative inputs.
Pro tip: Mention that using a heap with lazy deletion or a set to track seen values avoids duplicates efficiently, and that you can optimize by only pushing the next multiple when the current one is popped. This shows you think about performance and correctness.
Ask about input types (positive integers?), expected output order, handling of duplicates, and whether the stream is infinite. Confirm if next() should return the next multiple or if there's a reset method.
For one k, simply maintain a counter and return k * counter, incrementing counter each call. This is O(1) time and space.
Use a min-heap to store the next multiple for each base. Initially push each base. On next(), pop the smallest, then push the next multiple for that base (current + base). To avoid duplicates, skip if the popped value equals the last returned value.
Use a set or compare with last returned value to skip duplicates. Consider bases that are multiples of each other (e.g., 2 and 4) and ensure no duplicates. Handle zero or negative bases by clarifying or throwing exceptions.
Time: O(log m) per next() where m is number of bases, due to heap operations. Space: O(m). Mention that if bases are large, we could use a more advanced approach like a priority queue with lazy deletion or a generator-based merge.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.