Page Through a BST of SharePoint Item IDs in Order

Last updated: November 29, 2026

Quick Overview

SharePoint keeps item IDs in a binary search tree. Implement a pager that returns IDs in ascending order one page at a time, optionally starting from a given ID, using memory proportional to the tree height.

Microsoft
Coding & Algorithms
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


SharePoint keeps item IDs in a binary search tree. Implement a pager that returns IDs in ascending order one page at a time, optionally starting from a given ID, using memory proportional to the tree height.

An iterator design question that shows up in Microsoft technical screens, motivated by paginated list APIs. The interviewer checks that the candidate avoids materializing the whole traversal, gets amortized O(1) next(), and can seek to a start key.

What the Interviewer Expects
  • Use a stack of pending left-spine nodes
  • next() pops a node and pushes the left spine of its right child
  • Show amortized O(1) per next() and O(h) memory
  • Support a starting key by skipping subtrees below it
  • Return a short final page and signal the end
Key Topics to Cover
BST
iterator
in-order traversal
pagination
amortized analysis
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Make the pager resumable across stateless HTTP requests. What goes in the continuation token?
  • Support descending order.
  • What happens if the tree is modified between pages?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • BSTPager(root, low=None) starts at the smallest key >= low.
  • next_page(size) returns up to size keys; an empty list means done.
  • Memory must be O(h)....
High-Level Design

In-order traversal with an explicit stack can be paused at any point. The stack holds nodes whose left side is finished but which have not been returned. Popping returns the next key; then we push the...


Submit Your Answer
Markdown supported