The generator part itself wasn't the hard bit.
Start by clarifying the requirements and explicitly defining the generator's behavior for invalid inputs (skip, convert, or raise). Then implement a clean, documented generator that handles edge cases, and finally write comprehensive unit tests covering normal behavior, edge cases, iteration order, resource usage, and error handling.
Pro tip: In interviews, always state your assumptions about ambiguous requirements (e.g., what counts as an integer) and justify your design choices in terms of trade-offs like robustness vs. strictness. This shows you think like a senior engineer.
Ask clarifying questions about what to do with None, non-integers, and duplicates. Explicitly state your chosen policy (e.g., skip None and non-integers, yield duplicates as-is) and document it in the generator's docstring.
Write a generator function that iterates over the input list, applies the defined policy, and yields integers. Ensure it handles empty input gracefully and works with very large inputs by being lazy (not converting the entire list to a new list).
Code the generator with clear comments and a docstring explaining the behavior for each edge case. Use type hints to specify input and output types.
Create tests for normal behavior (list of ints), edge cases (empty list, all None, all non-ints), duplicates, large inputs (e.g., using a generator to simulate), iteration order, and error handling (if raising is chosen). Use a testing framework like pytest.
Explain why you chose skip/convert/raise, and how the generator is memory-efficient for large inputs. Mention that tests for resource usage can be done by checking that the generator doesn't consume excessive memory (e.g., using tracemalloc or by design).
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.