Amazon Interview Question
Software Engineer / DevelopersCountry: India
Use hash table where the hash function returns a number in which few bits come from name, few from phone and few from address,
For e.g. suppose hash function for name return a number in range [0,39] say 14,
hash function for phone number returns a number in range [0,9] say 3,
hash function for address returns a number in range [0,9] say 5.
So the entry will hash in bucket 1435.
To search a phone number, given the value returned by the hash function for phone
number say 7, then search all buckets of form xx7x.
For generating the bucket numbers, use a for loop in this manner
for(i=0;i<40;i++)
{
for(j=0;j<10;j++)
{
int sum = i*100 + z*10 + j; //Here z=7 and z is already supplied
}
}
how about using suffix tree. if we are using hash in order to search anything we need to enter correct and complete value. example if i'm searching for number "9912345678" then i need to enter correct value then only i'll be able to fetch all the data.
Assumption: we are designing this data structure for smartphones.
Have 3 hash tables named PhoneMap, NameMap and AddressMap linked to each other.
- PRB September 13, 2011unordered_map<string,string> AddreddMap;
unordered_map<string, AddreddMap::iterator> NameMap;
unordered_map<string, NameMap::iterator> PhoneMap;
With any input, we can look up the remaining two in O(1).