Implement O(1) randomized multiset
TikTokSoftware Engineer · Technical ScreenLast updated
Implement O(1) randomized multiset evaluates algorithm design, data structures, correctness, complexity, edge cases, and implementation details in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.
Write code for a data structure that supports add(x), remove(x), and getRandom() in average O(
- time where duplicates are allowed, and getRandom returns an element with probability proportional to its multiplicity. Explain your design, analyze time/space complexity, and discuss edge cases and randomized testing.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.