Implement Infinite Fibonacci Generator Using Lazy Evaluation
Company: Citadel
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: This question evaluates understanding of lazy evaluation and Python generator semantics, testing a candidate's ability to work with iterative sequence production and manage state across iterations.
Constraints
- 0 <= n <= 100000
- Use a generator with yield to produce Fibonacci numbers lazily
- Do not use recursion
- Time complexity must be O(n)
- Extra space complexity must be O(1) besides the output list
- Python integers can grow arbitrarily large
Hints
- Maintain two variables a and b; yield a then update a, b = b, a + b
- Use a while True loop to create an infinite generator and take only n values
- Edge case: when n is 0, return an empty list