Interview Question

Fibonacci series

Generate Fibonacci values iteratively by updating two running values.

💡 Concept ✅ Quick Revision 🐍 Python

Answer

The Fibonacci sequence starts with chosen seed values and each later value is their sum. • A common programming version starts with 0 and 1. • An iterative generator avoids repeated recursive work. • The requested count should be validated.

💡 Simple Example

def fibonacci(count): a, b = 0, 1 for _ in range(count): yield a a, b = b, a + b print(list(fibonacci(7)))

Output

[0, 1, 1, 2, 3, 5, 8]

⚡ Quick Revision

Generate Fibonacci values iteratively by updating two running values.