Google Interview Question for Software Engineer / Developers


Country: United States




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

We can use suffix tree (or) trie. Given the fact that many of the phone numbers will have the same prefix. The height of suffix tree would be 10 (+1 empty root node).

- Mario September 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

FAIL. Giving an answer without clarifying the question. The other answer has it right. You need to figure out the scenario/underlying question first.

- Anonymous November 09, 2012 | Flag
Comment hidden because of low score. Click to expand.
2
of 2 vote

What is the scenario?

- Anonymous September 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Right. Depends on the scenario.

Is it storing for ftp transfer to 100 other machines?
Will you run queries on that later? etc etc

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

Yes, really depends on what you want to do with these and if there are any patterns.

If the numbers tend to be assigned in batches you could just the numbers where the batches begin and end.

ie.
//until 416 200 0999 are unused
// 416 200 1000 to
// 416 300 0999 are in use
phone[0] = 416 200 1000;
phone[1] = 416 300 0999;
phone[2] = <next number in use>
phone[3] = <next number not in use>


If space is not at a premium just assign a boolean to each element indexed by the phone number.
i.e. as many indices as the largest phone number..

(you can still reduce by /8 by using every bit per byte)

- pokermace September 29, 2012 | Flag
Comment hidden because of low score. Click to expand.
2
of 2 vote

use bit-maps

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

I feel a Trie serves Better than a Suffix Tree.
We wont need to store the prefixes at all, only the number in its entirety should be stored.
Taking advantage of the common prefix, I think a trie is a better go.

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

BST

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

Can anyone describe in detail, the alternative option (other than trie)?

- technical_123 August 14, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 4 vote

The key here is that 1 million phone numbers will be within some range, likely 10 million or so. 10 million bits = 10^7 bits ~ 0.12 GB. Just have a bit array where the first bit being set implies that the first phone number is set (e.g., 10 000 000) and the last bit indicates the last phone number (10 999 999). If you find a number in the list, just set the appropriate bit. You now have a bit vector of size 1million bits, sorted, and to check for a particular number, you just check whether the corresponding bit is set.

- jayram singh September 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

R u suggesting an array of 1million boolean data? I dont think tht will be feasible

- anshulzunke September 04, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is not the best solution. The phone numbers are typically 13 digits in size, should mean a vector of size 10^13. You can not just create a bit vector of same size as number of phone numbers, you can not map it back to corresponding number.
Secondly, I assume interviewer is expecting more of STORAGE - as in saving it in database or file (XML file or regular file).

- Dilbert Einstein September 04, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Am I missing something? 10^7 bits should be roughly 1.2*10^6 bytes, which is 1.2M bytes, not 0.12GB(120MB).

- Richard September 05, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

1 million = 10^6

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

you better try to read question, It's not asking to sort a million phone numbers

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

lol

- saurabh September 23, 2012 | Flag


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