PracHub
QuestionsLearningGuidesInterview Prep

Quick 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.

  • medium
  • Citadel
  • Coding & Algorithms
  • Data Scientist

Implement Infinite Fibonacci Generator Using Lazy Evaluation

Company: Citadel

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

##### Scenario Testing understanding of Python lazy evaluation and generators. ##### Question Explain what lazy evaluation means in Python and implement a generator using "yield" that produces an infinite Fibonacci sequence. ##### Hints Show how state is preserved between yields and why values are computed only when requested.

Quick Answer: 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.

Implement lazy_fibonacci(n) that returns a list of the first n Fibonacci numbers starting at 0. Internally, use a generator with yield that produces an infinite Fibonacci sequence and collect only the first n values. The sequence must be 0, 1, 1, 2, 3, ...

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

  1. Maintain two variables a and b; yield a then update a, b = b, a + b
  2. Use a while True loop to create an infinite generator and take only n values
  3. Edge case: when n is 0, return an empty list
Last updated: Mar 29, 2026

Loading coding console...

PracHub

Master your tech interviews with 9,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Perform an External Merge Sort with a Heap - Citadel (medium)
  • Find the Index Range of a Target in a Sorted Array - Citadel (medium)
  • Top-K Largest Elements in Every Sliding Window - Citadel (medium)
  • Sort a Nearly Sorted Array - Citadel (hard)
  • Implement a single-producer multi-consumer ring buffer - Citadel (medium)