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

Question

Design a set supporting insert(x), remove(x), and get_random() each in average O(1). Since randomness is hard to test deterministically, instead of true randomness, get_random must return the element currently stored at internal index (call_counter % current_size) where call_counter starts at 0 and increments on each get_random call. insert returns 1 if x was newly added (0 if already present); remove returns 1 if x was present and removed (0 otherwise). Replay ["insert", x], ["remove", x], ["getRandom"] and return the list of all results in order.

Implement
random_set(ops: list[list]) → list[int]
Examples
in[[["insert",1],["remove",2],["insert",2],["getRandom"],["remove",1],["insert",2],["getRandom"]]]out[1,0,1,1,1,0,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.