Sample Flight Devices With Constant-Time Insert, Remove and Random Pick

Last updated: November 29, 2026

Quick Overview

Design a set of device IDs for Windows Insider flighting that supports insert, remove and returning a uniformly random member, each in average O(1) time.

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

0

0

0 solved


Design a set of device IDs for Windows Insider flighting that supports insert, remove and returning a uniformly random member, each in average O(1) time.

A Microsoft technical screen data structure question framed around picking random devices from a rollout pool, as Windows flighting does when staging an update. The interviewer wants the array-plus-index-map idea and, above all, a correct swap-with-last removal.

What the Interviewer Expects
  • Explain why neither a hash set nor a list alone is enough
  • Keep a list of values and a map from value to index
  • Remove by swapping with the last element and popping
  • Update the moved element's index before deleting
  • Handle duplicate inserts and missing removes
Key Topics to Cover
hash map
dynamic array
randomization
data structure design
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
  • How would you support duplicates, returning each copy with proportional probability?
  • How would you pick a random device weighted by a per-device score?
  • How would you make this safe for concurrent callers?
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

insert(x) adds x if absent and returns whether it was added. remove(x) deletes x if present and returns whether it was removed. pick() returns a uniformly random current member and is only calle...

High-Level Design

A hash set gives O(1) insert and remove but no O(1) random access. A list gives O(1) random access by index but O(n) removal from the middle. Combine them: the list holds the values densely, and a dic...


Submit Your Answer
Markdown supported