Join waitlist
C++Community question

unordered_map got hacked on codeforces

Asked by Karthik Rajan 1 month ago 2 answers 7 votes

same solution with map passed. how is O(log n) beating O(1)

2 answers

Arjun Mehta1 month agoMost voted6

anti hash test. someone made inputs that all collide so every operation became O(n). use a custom hash (splitmix64 with a random seed) or just use map

Tushar Goyal1 month ago2

map also gives sorted order and lower_bound, half the time that's why I use it anyway

Related questions

Go deeper

Want the full explanation, not just an answer?

Structured lessons on DSA, core CS, Java and interview skills, each ending in a quiz so you know it stuck.