Meta Interview Problem #4 — Implement a Multiset (Bag)

Problem (verbatim):
“A multiset (also known as a bag) is a mutable, unordered collection of distinct objects that may appear more than once in the collection.

Implement a multiset that implements the following methods:
• add(element)
• remove(element)
• count(for: element)”

English summary (concise approach):
Back the multiset with a hash map value → frequency.

  • add(e): increment frequency.
  • remove(e): decrement if present; delete key at zero (ignore if absent unless spec says otherwise).
  • count(e): return frequency or 0.
    All ops are amortized O(1); space is O(#unique).

The VOprep team has long accompanied candidates through various major company OAs and VOs, including OpenAI, Google, Amazon, Citadel, SIG, providing real-time voice assistance, remote practice, and interview pacing reminders to help you stay smooth during critical moments. If you are preparing for Stripe or similar engineering-focused companies, you can check out our customized support plans—from coding interviews to system design, we offer full guidance to help you succeed.

END
 0