Design dynamic weighted random sampling with updates
Company: Citadel
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Quick Answer: This question evaluates a candidate's ability to design and analyze dynamic data structures that support weighted random sampling with inserts and deletes, testing skills in algorithm design, complexity analysis, and randomized sampling under large numeric constraints.
Constraints
- 1 <= len(operations) <= 100000
- 1 <= weight <= 10^9 for insert operations
- IDs are integers and may be sparse or large in magnitude
- The total active weight can exceed 32-bit integer range
- Insert on an existing ID must be treated as a weight update
- Delete on a missing ID is a no-op