Lazy Iterator Over Nested OneDrive Folder Listings
Last updated: November 29, 2026
Quick Overview
A OneDrive listing is a nested list where strings are file names and lists are subfolders. Implement an iterator with `has_next()` and `next()` that yields file names in depth first order, lazily, without flattening everything up front.
Microsoft
November 29, 20260
0
0 solved
A OneDrive listing is a nested list where strings are file names and lists are subfolders. Implement an iterator with `has_next()` and `next()` that yields file names in depth first order, lazily, without flattening everything up front.
Microsoft onsites often ask for iterator design because the .NET IEnumerable model is central to how teams write APIs. The interviewer checks lazy evaluation, a correct `has_next` that skips empty folders, and idempotent repeated calls.
What the Interviewer Expects
- Use a stack of child iterators instead of flattening eagerly
- Make has_next advance past empty folders and buffer the next file
- Ensure calling has_next repeatedly does not skip elements
- Raise or signal correctly when exhausted
- Discuss memory: O(depth) rather than O(total files)
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you support remove() on the current element?
- How would you make it resumable across process restarts using a continuation token?
- What if subfolders are fetched from a paged remote API?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: nested Python list of strings and lists, arbitrarily deep, possibly with empty lists.
next()returns the next file name in depth first, left to right order.has_next()returns whether...
High-Level Design
Keep a stack of iterators, one per folder currently being walked. The top iterator is the deepest open folder. To find the next file, call next on the top iterator:
- If it is exhausted, pop it and...