Google Interview Question for Software Engineer / Developers






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

We could create a hash table on names, then each element of the hash table can be another hash table on last names. This would be O(1) ideally. Of course we should have another data structure that hashes on last names and then on first names.

- Igor September 12, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Good solution.

- gavinashg September 23, 2011 | Flag
Comment hidden because of low score. Click to expand.
3
of 3 vote

I guess a solution better than O(N) must be obtained using TRIES (prefix trees).
We can arrange all the names and surnames in 2 different tries.
But here also we will require a connection between two tries. Can anybody suggest a solution?

- PQ August 04, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

The end of the first name letter should point to the start of the second trie which has second name.

- S August 21, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

one Trie with two entry of same name; first name+last name & last+first;

- Saki August 05, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

lol

- Anonymous April 17, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think this is good one

- Avinash November 04, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

If we have all names in sorting order (priority given to first name and then last name), then we can use binary search tree to find the given name. then it is less than O(N).

- Gopal August 08, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Lol :P

- Loler August 20, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

is it? :P :P

- Anonymous December 09, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

is it? :P :P

- Anonymous December 09, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Person is an object which has to be searched and accessed using his name / surname / name+surname.

So an O(logN) solution is possible by creating three sorted arrays one for name, another one for surname and another one for full name. And each will have the pointer to the person object. A binary search will be sufficient for that.

An O(1) solution is possible if we take hashtable or map for all of the three.

- deepak August 20, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Trie will have worst case time complexity as O(n). So We should use 3 balanced binary search tree like AVL tree or red black tree where building the tree will take n*log(n) time and searching will take log(n) time and space complexity would be O(n).

- Gaurav August 30, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think trie would be a better approach along with @Gaurav's approach

- jaldeep.lancer September 23, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

useless comment ..!!

- freelancer October 16, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Trie might be better than hash tables. Hash tables aren't good with phone book type entries.

- lazy November 06, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Create a kd tree on (first name, last name). If the kd tree is balanced then search would be O(log n)

- manujoseph August 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Two hashtables. One with key for First Name and other with key for Last Name with both values pointing to same Person object.
For each bucket store items in BST, sorted by the "other" name.
So when searching for complete name, we can do O(1) for First Name and then O(lg n) to find Second Name (or vice versa).

- philippppe September 08, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

suffix tries can be used. Use <FirstName> : <LastName> and now you can even search on substrings, suffixes etc.

- Anonymous July 25, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

This simply is impossible unless the names are unique. If they are, a simple hash table would work.

- memo August 04, 2011 | 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