We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Changing the boilerplate is unnecessary to avoid a timeout.
Rather you can keep two hashmaps where the keyset of one is the set of integers in the array and the keyset of the other is the set of frequencies with which integers appear in the array.
This allows you to perform all operations using keys rather than values, which is efficient enough that it doesn't timeout.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Frequency Queries
You are viewing a single comment's thread. Return to all comments →
Changing the boilerplate is unnecessary to avoid a timeout.
Rather you can keep two hashmaps where the keyset of one is the set of integers in the array and the keyset of the other is the set of frequencies with which integers appear in the array.
This allows you to perform all operations using keys rather than values, which is efficient enough that it doesn't timeout.