Please read the new rule regarding the restriction on the use of AI tools. ×

How to iterate through hashmap efficiently?

Revision en1, by AkeenL, 2021-04-03 23:59:41

For problem BerPizza https://codeforces.me/contest/1468/problem/C the most easy solution is to store the key and values in a hashmap and loop through looking for either largest value or smallest index. This approach gives TLE and when I read the editorial they recommend a treeset but a treeset cannot store duplicate values. Is there a way to iterate through a map faster than o(n) or do I need to use priorityqueues for this problem?

Tags #data structure, #implementation

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English AkeenL 2021-04-03 23:59:41 481 Initial revision (published)