Constant-Time Set Operations
Updated
Problem statement
Process a sequence of operations on an integer set. PUT x inserts x only when it is not currently present. GET x appends true or false to the returned array. ITERATE appends one comma-separated string containing the current values in first-insertion order, or an empty string when the set is empty. CLEAR removes every current value. The paired integer is ignored for ITERATE and CLEAR.
Use expected constant time for each PUT, GET, and CLEAR, and constant time to obtain the start of an iteration. Materializing an ITERATE result may take time proportional to the number of emitted values.
Function
processConstantTimeSet(operations: String[], values: int[]) → String[]Examples
Example 1
operations = ["PUT","PUT","GET","ITERATE"]values = [4,7,4,0]return = ["true","4,7"]The membership query finds 4, and iteration preserves first-insertion order.
Example 2
operations = ["PUT","CLEAR","GET","PUT","ITERATE"]values = [9,0,9,3,0]return = ["false","3"]CLEAR invalidates the prior generation in constant time before 3 starts the new insertion order.
Constraints
1 <= operations.length == values.length <= 200000operations[i] is PUT, GET, ITERATE, or CLEARvalues[i] is a signed 32-bit integervalues[i] is ignored for ITERATE and CLEARthe total number of values emitted by ITERATE operations is at most 200000
More Pure Storage interview questions
- One-Shot Callback Event DispatchONSITE INTERVIEW · Seen Sep 2026
- Rasterize a Circle with Integer PixelsONSITE INTERVIEW · Seen Sep 2026
- Racing ResultsOA · Seen Oct 2024
- Find DoublesOA · Seen Oct 2024
- Perfect AND Tree Leaf UpdatesONSITE INTERVIEW · Seen Aug 2024
- Set Command SimulationONSITE INTERVIEW · Seen Aug 2024
- Count Different Palindrome SubstringsOA · Seen Jul 2024
- Count Palindromic SubstringsOA · Seen Jul 2024
- Find RepetitionsOA · Seen Nov 2023
- Bakery Quality ControlOA · Seen Nov 2023
Similar questions at other companies
- LRU CacheAthenahealth · PHONE SCREEN
- LRU CacheApple · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
- LRU Cache for Query ResultsAmazon · PHONE SCREEN · ONSITE INTERVIEW
- LRU CacheServiceNow · PHONE SCREEN · ONSITE INTERVIEWServiceNow interview questions
- Balanced Session ManagerPalantir · PHONE SCREENPalantir interview questions
- LRU CacheGimlet Labs · PHONE SCREEN
- LRU CacheBNSF Railway · PHONE SCREENBNSF Railway interview questions
- Max Frequency TrackerProcol · PHONE SCREEN
- LRU Cache Operation SequenceCARS24 · PHONE SCREEN
- LRU Key-Value Cache OperationsCohesity · PHONE SCREEN