Amazon Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
1
of 1 vote

What if someone wants to search by address or company name or any attribute other than name or number ?

I think we need to create trie. There will be contact object.
Contact {
String Name,
String lastName,
String companye,
int[10] phone,
int[10] mobile ...
String address( we can also create address object and add more details if we want)}

there will be seperate trie for each attribute pointing to this object. So phoneTrie, nameTrie,
..etc.
For every update/delete/insert these trie will be updated.

- kasi.beck March 22, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

We create a tree data structure,
the tree is a general tree with at max 26 children, and
each node also store a bool variable(is used for telling weather number present here or not) and a string (used to tell contact number along with code number).
and choose child function(which uses char to identifies the children)
Here is insert methods

we start with root node, and move from root node to children's according to each char.
for example if user name is "sonesh", then from root node it go to "s"th children, then from "s"th node it go to "o"th children and so on.
when we reach to "h"th node, 
In this if at any point we does not get require children, then we create that children, and move to that children.
we set bool variable to true, 
and set string variable to sonesh's number.

Now we can easily able to extend it to have multiple contacts with same name, or we can easily able to restrict it, Here we can also consider "space" as a char.
Now get contact can also be implemented very easily,
Here both insert and get have constant complexity(O(1)).

- sonesh March 22, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

use hash table and name as key.

- outdoor March 22, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

search is definitely will better in case of hash but sorting the contact will create a issue here..

- khetan March 31, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Shouldn't phone number is better as Key rather than Name, it's very likely to have two contacts of same name but not possible for two contacts has same phone number.

- Forgotten April 05, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I would generate integer ids for names and phone numbers that get entered into the mobile phone. (I know phone numbers are already integers, but the ids would be shorter.)

Then maintain two parallel maps:

name id -> phone number id
phone number id -> name id

You could implement the maps as hashes, or you could implement them as simple arrays and do binary search. If you go the array route (an array of tuples of ints), then lookups in both directions will be log N, displaying the contact list ordered by name will be O(N), and insertions/deletions/edits will be O(N), but you'll dealing with ints, so they'll be fast.

If you're mostly dealing with lookups, then a hash will be sufficient, but if you are frequently displaying contact names, then you'll want some sort of auxiliary data structure that has the names already in order (either explicitly via an array or implicitly via a binary tree).

- showell30@yahoo.com March 22, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use Trie to store the names and the number as part of the last node in the trie. This way a prefix can get all the phone numbers.

- Anonymous March 22, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

maintain 2 tries.. one for names and one for phone numbers...so while we are typing a phone number, we can give matched names up to typed numbers...

- bharat March 23, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use a multimap

#include <map>

int main()
{
    std::multimap<string, int> myAddressBook;

    myAddressBook.insert( pair<string, int>("Bob", 5551212));
    myAddressBook.insert( pair<string, int>("Bob", 5551234));
    myAddressBook.insert( pair<string, int>("Jennie", 8275309));
    myAddressBook.insert( pair<string, int>("Sally", 5559873));

    std::multimap<string, int>::iterator it = myAddressBook.find("Jennie");

    std::cout << "Phone number for Jennie is" << it->second << '\n';
}

- Darrell March 31, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Tree maps can be used for this purpose.

TreeMap tm = new TreeMap();
// Put elements to the map
tm.put("John Doe", new Double(3434343434));
tm.put("Tom Smith", new Double(1232212322));
tm.put("Jane Baker", new Double(1378000823));
tm.put("Todd Hall", new Double(9922234567));
tm.put("Ralph Smith", new Double(1908123456));
// Get a set of the entries
Set set = tm.entrySet();
// Get an iterator
Iterator i = set.iterator();
// Display elements
while(i.hasNext()) {
Map.Entry me = (Map.Entry)i.next();
System.out.print(me.getKey() + ": ");
System.out.println(me.getValue());
}

And to get a particular phone number:

System.out.println("John Doe's phone number is: " +
tm.get("John Doe"));

- jano April 04, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use Suffix Trees...If you want that your search should continous stream with no delimiters,else use compressed tries.

- bharat May 05, 2013 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More