shivanshsingh9670's blog

By shivanshsingh9670, history, 20 months ago, In English

Question

In my both solutions, i am storing the frequencies of the values in maps and then pushing in priority queue. When I use unordered_map, it throws tle. But if I use map, it is accepted. Can someone explain Why ?

Unordered_map Solution — TLE

Map Solution — Acceppted

  • Vote: I like it
  • +4
  • Vote: I do not like it

»
20 months ago, # |
  Vote: I like it +11 Vote: I do not like it

This is a very common mistake for beginners. All people think that unordered_map time is O(1), but actually average time is O(1). When storing large prime numbers, the time can get up to O(n)