← Citadel Interview Insights

Citadel·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Citadel Data Scientist technical screen, pretty focused on Python internals. One question, but they really wanted you to go deep on it rather than just sketch something out.

Questions Asked (1)

Q1

What does lazy evaluation mean in Python, and can you write a generator using yield that produces an infinite Fibonacci sequence?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The infinite part is what tripped me up mentally at first.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining lazy evaluation as delaying computation until values are needed, emphasizing its benefits for memory and performance. Then, write a generator function using yield that produces Fibonacci numbers indefinitely, explaining how each call to next() computes the next value on demand. Finally, connect this to data science scenarios like processing large datasets or streaming data.

Pro tip: Mention that generators maintain state between yields and are memory-efficient, which is crucial for handling large-scale data at Citadel. Also, note that infinite generators require careful handling to avoid infinite loops in practice.

1. Define lazy evaluation

Explain that lazy evaluation defers computation until the result is actually needed, contrasting it with eager evaluation. Highlight advantages such as reduced memory usage and ability to work with infinite sequences.

2. Introduce generators and yield

Describe generators as functions that produce a sequence of results lazily using yield. Explain that yield pauses the function and saves its state, allowing resumption.

3. Write the Fibonacci generator

Present a generator function that initializes a, b = 0, 1 and loops indefinitely, yielding a and updating a, b = b, a+b. Emphasize that it produces an infinite sequence without storing all values.

4. Demonstrate usage and benefits

Show how to consume the generator, e.g., using next() or itertools.islice to take the first n values. Discuss memory efficiency and suitability for streaming data.

5. Relate to data science context

Connect lazy evaluation to data science tasks like reading large files line by line, processing data streams, or implementing pipelines with generators to avoid loading everything into memory.

Key Points to Mention

  • Lazy evaluation delays computation until needed, improving memory and performance.
  • Generators use yield to produce values one at a time, maintaining state between calls.
  • The Fibonacci generator can be written as: def fib(): a, b = 0, 1; while True: yield a; a, b = b, a+b.
  • Infinite generators are safe if consumed lazily; use islice or takewhile to limit.
  • Generators are ideal for large datasets or streaming data in data science.
  • Python's generator expressions and functions enable lazy pipelines.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.