Google Interview Question for Software Engineer / Developers


Country: United States




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

using hash table to store the query body and occurrence, it can be done in O(n) time. And then keep a min heap of 10 capacity to find the top 10. If the new one is bigger than the top of our min heap, it can replace the min heap top and keep the min heap property in O(log10). The total time would be O(n+n*log10), at most O(n)

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

store in two tables like:

| Query Id | Query Body |
and
| Query Id | Query Date | Occurrence

initialize min heap of size 10;
for each query:
select sum(Occurrence) as qo where query date is in the given interval and query id = current query id
remove the heap min
place (qo, query id) node in the min heap

in the end the heap will contain top 10 queries made during the given dates interval.

- S.Abakumoff February 11, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

select id, sum(Occurrence) from table where date>x and date<y group by id

- zyfo2 February 12, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

funny, when I think about it - DB would be the solution in real world. But the interviewer directed to use Hash-table. When the hash function is unknown but maps strings to bits combinations.

- adam2008 February 12, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@adam, could you please explain more in detail what is the bits combinations and how to come up with the result with certain days? Thanks.

- zilchistDeepblue February 13, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

it means: we can find a hash function that maps english words to 2 byte value (the picture enables 2^ 16 different binary words, more that needed for the english language). Then a sentence is mapped to a btye[] or even long type. This is the key for the hash table. teh value is a counter. We keep aside the max counter + it's key. At any moment we can print it.

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

I think it can be done simply using Hash-map. You can store the key as the query and value as the occurrence of the same. Then just apply sorting on values and get the key for the top 10 ones.

- Aditya February 26, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i think the interviewer also focus on the memory problem. What if the hashmap cannot contain all of these queries? Like how to eliminate the queriese if the memory cannot hold all of these queries, etc.

- aileen May 04, 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