I got the basic generator working fine, two variables, yield, loop forever.
Start by clarifying the requirements and then implement a generator function that yields Fibonacci numbers indefinitely, using constant memory. Explain how generators maintain state and produce values lazily, contrasting with precomputed lists that store all values. Optionally, discuss adding parameters for count or upper bound and how that affects memory and termination.
Pro tip: Emphasize that generators are ideal for infinite sequences because they compute values on demand, but be prepared to discuss the trade-off of not being able to access arbitrary elements without iterating. Also, mention that adding a bound parameter can make the generator finite and more practical for some use cases.
Ask if the generator should be infinite or support a count/upper bound, and confirm the expected interface (e.g., function that returns a generator).
Write a generator function using yield to produce Fibonacci numbers indefinitely, maintaining only the last two numbers in variables.
Explain that the generator uses O(1) memory because it only stores the current and previous Fibonacci numbers, while a precomputed list uses O(n) memory.
Describe how generators produce values on demand, enabling infinite sequences and avoiding unnecessary computation, unlike lists which compute all values upfront.
Optionally, show how to add a count or upper bound parameter to limit the generator, and discuss how that changes memory and termination behavior.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.