GO TO A SECTION

↑ ↓ to navigate · Enter to openExplore all sections →
FDEInterviews logo
← Coding & DSA / 61
easyOpenAIAnthropicHugging Face

Write a generator that yields fixed-size batches from a large iterator for streaming inference.

Batching inputs is how you keep a GPU fed, but the source is an iterator you cannot index or len(). The warm-up that screens whether you can write a lazy generator that handles the ragged final batch.

Updated Aug 2026 · Grounded in real Forward Deployed Engineer interview loops and written to a senior-engineer editorial bar.

Batching inputs is how you keep a GPU fed, but the source is an iterator you cannot index or len(). The warm-up that screens whether you can write a lazy generator that handles the ragged final batch.

20 answers per topic instead of 10, plus saved progress and bookmarks · no cardor unlock all 548 remaining answers · ₹2,000 / $25

Every answer, concept and course, every paper breakdown, all published video lessons, hands-on FDE Lab missions, Premium PDF guides and companion files, the full practice-test bank and work-sample downloads. Referral Premium excludes guide PDFs and their companion files.

6 months · One payment · No auto-renewal

Study alongside free video lessons.

Keep practising

FEDITOR'S NOTE

Two tells separate a clean answer. First, indexing into the source (data[i:i+n]) when the prompt says iterator, which fails the moment the input is a generator or a 100GB file you cannot slice. Second, dropping or duplicating the last partial batch. The senior instinct is islice or a manual accumulator that yields whatever remains when the source is exhausted, and a parameter for whether the caller wants that partial batch at all.

DISCUSSION · 0

No comments yet — be the first to share your approach.