Code Room
CodingMediumcod-g116
Subject Design data structuresLevel Mid–Senior~30 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

Design a data structure supporting insert(x), remove(x), and getRandom(), each in average O(1) time, where getRandom returns a uniformly random current element. Insert returns True if the value was newly added (False if already present); remove returns True if the value was present and removed (False otherwise). To make the result deterministic for grading, getRandom is replaced by getAt(i) which returns the element currently stored at internal slot i of the backing array (0-indexed). Given a list of operations (each a list like ['insert', 3], ['remove', 3], ['getAt', 0]), return the list of results in order. There are 1 to 10^4 ops; values fit in 32-bit signed range.

Implement
run_random_set(ops: list[list]) → list
Examples
in[[["insert",1],["remove",2],["insert",2],["getAt",1],["remove",1],["insert",2],["getAt",0]]]out[true,false,true,2,true,false,2]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.