Yahoo Interview Question Software Engineer / Developers




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

~ read the document - O(n)
~ maintain a hashmap, and hash the strings as keys with initial count of 1 if the current term isnt present else increment the bucket count by 1 - O(1)
~ sort the map by values - O(n log n)

- son_of_a_thread on August 03, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Our map should be of the form <word, pair<count, pointer>>. This pointer should be an index to a heap structure of size k (5 here). We should maintain a min - heap, every time the count of a word is greater than root of the heap we remove the minimum count seen and replace it with the current value and max-heapify. Cost of max-heapify is lg k. Even if we have to max-heapify after reading every word, the complexity will come out to be O(n lg k) whereas in case of sorting it'd be O (n lg n).

- Second Attempt on February 17, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

the min-heap is a really smart way. the map is just use to store the counts of the word appear

- brady on May 01, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

1)read the document and build a tree of words with its count
2)the bst should contain words in lexicographical ordering
3)increment each count of the word if it is fount in the tree otherwise add it in the tree
4)sort this tree.

- Anonymous on June 23, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

novel approach but building a tree and searching for the contents of the tree takes O(log n) time.. hashing is preferable? Insertion and searching takes O(1)

- son_of_a_thread on August 03, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hashing aint the sol for everything. Could you imagine the space complexity behind hashing.

- anshulzunke on September 17, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

use trie and maintain count at the end of words

- keshav on January 06, 2013 | Flag Reply


Add a Comment
Name:

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

Books

is a comprehensive book walking you through 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