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

Question

Design an ordered multiset supporting ['add', x], ['remove', x] (remove one occurrence; no-op if absent), and ['rank', x] which returns the number of stored elements strictly less than x. Keep the structure sorted so each query is logarithmic in lookup. Given an op list, return the list of results for each 'rank'.

Implement
ordered_multiset(ops: list[list]) → list[int]
Examples
in[[["add",5],["add",3],["add",8],["rank",5],["add",5],["rank",5],["rank",9]]]out[1,1,4]
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.