Code RoomOrdered multiset range count
MediumPrep Room Coding #902

Ordered multiset range count

CodingDatabases & SQLAlgorithms & data structuresMid–Senior~25 min

Implement an ordered multiset that processes a list of operations and answers range-count queries. Each op is one of: ['insert', x], ['remove', x] (removes one occurrence if present, else no-op), or ['count', lo, hi] which asks how many stored values v satisfy lo <= v <= hi (inclusive). Values are integers and duplicates are allowed. Return a list with one integer per 'count' op, in order. Assume up to ~10^5 ops.

Implement
ordered_range_counts(ops: list[list]) → list[int]
Examples
in[[["insert",5],["insert",3],["insert",8],["count",3,8],["remove",5],["count",3,8],["count",1,2]]]out[3,2,0]
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
[[["insert",5],["insert",3],["insert",8],["count",3,8],["remove",5],["count",3,8],["count",1,2]]][3,2,0]not run yetsample