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.
I solved it in a very different way, and very much a "hack" that is solving it only based on the problem given, not a real-world solution. We don't actually store contacts in our system, we're storing indexes. So instead of expecting to actually get the contacts back, we're just getting a count. That plus knowing searches aren't more than 6 chars long makes things trivial:
Which obvously the findContacts() function executes super fast as it is using a native primitive for the hash lookup. Passing on all accounts. No fancy tree/splitting needed.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Tries: Contacts
You are viewing a single comment's thread. Return to all comments →
I solved it in a very different way, and very much a "hack" that is solving it only based on the problem given, not a real-world solution. We don't actually store contacts in our system, we're storing indexes. So instead of expecting to actually get the contacts back, we're just getting a count. That plus knowing searches aren't more than 6 chars long makes things trivial:
This gives trees like:
Which obvously the findContacts() function executes super fast as it is using a native primitive for the hash lookup. Passing on all accounts. No fancy tree/splitting needed.