Anonymous · shared experience1 Oct 2025 · 3 views
Teradata: O(1) insert, delete and get-random, then allow duplicates
Problem. Design a data structure that supports insert, delete, search and returning a random element, each in average O(1) time. No duplicates at first.
Follow-ups.
- If you cannot use the language's built-in random class, write your own random number generator.
- Change the design so duplicates are allowed.
Approach. An array of values plus a hash map from value to index; delete by swapping the target with the last element and popping. For duplicates, map each value to a set of indices.
Comments 0
No comments yet. Ask the author something, or add what happened in your own round.