Code RoomOrdered multiset
MediumPrep Room Coding #1343

Ordered multiset

CodingAlgorithms & data structuresMid–Senior~25 min

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.

0:00 of about 25 min
InputExpectedGot
[[["add",5],["add",3],["add",8],["rank",5],["add",5],["rank",5],["rank",9]]][1,1,4]not run yetsample