Add, Remove, and Find Values in a Bounded Integer Universe
Company: Amazon
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: Implement constant-time bounded-integer set operations with direct addressing, explicit duplicate semantics, initialization cost, and sparse-universe tradeoffs.
Constraints
- 1 <= limit <= 1000000; every decimal-string value represents an integer in [0,limit).
- At most 200000 operations, each [ADD,value], [REMOVE,value] or [CONTAINS,value].
- The set begins empty. ADD reports a new insertion, REMOVE reports an existing removal, and CONTAINS reports membership.
- Return one boolean per operation; use direct bounded state with worst-case constant-time set access after initialization.
Examples
Input: (5, [['ADD', '2'], ['ADD', '2'], ['CONTAINS', '2'], ['REMOVE', '2'], ['CONTAINS', '2'], ['REMOVE', '2']])
Expected Output: [True, False, True, True, False, False]
Explanation: The source sequence separates duplicate insertion, removal and membership.
Input: (1, [['CONTAINS', '0'], ['ADD', '0'], ['REMOVE', '0'], ['ADD', '0'], ['CONTAINS', '0']])
Expected Output: [False, True, True, True, True]
Explanation: The sole value can be removed and reinserted.