Yahoo Interview Question for Software Engineer / Developers






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

Description does not make sense. Task was to display number of 1,2,3,4 lettered words, so example would be

5 2
4 1
2 1

where fist number of each row is a number of letters in a word and second is number of words with this many letters in a paragraph.

- Alexei January 29, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Make B+ tree .. and disply in sorted order..

- DK January 28, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

+1..

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

Hash table

- Anonymous January 28, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class outputwords {

@SuppressWarnings("unused")
private String words[];

public outputwords(int InitNum){
words = new String[InitNum];
}

public void addToken(int pos, String Token) {
words[pos-1] = Token;
}

public String toString() {
StringBuffer s = new StringBuffer();
for(int i=0;i<words.length;i++) {
if(words[i] != null) {
s.append(words[i] + " ");
}
}
return s.toString();
}

public static void main (String args[]) throws Exception {

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
outputwords mywords = new outputwords(10);
String buffer = reader.readLine();
while(!buffer.equalsIgnoreCase("/output")) {

int period_pos = buffer.indexOf('.');
int pos = Integer.parseInt(buffer.substring(0, period_pos));
mywords.addToken(pos, buffer.substring(period_pos+1));
buffer = reader.readLine();
}
System.out.println(mywords.toString());
}

}//end class

- saimok January 29, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If the count alone is required, Hash table is the solution. Traverse the paragraph once and then display the count accordingly.

If the words need to be displayed. Hashmap<int count, vector words> is enough.

Question is about search. Then a TRIE is the best solution. for the entered words we can search and display if it reaches the end of a word. else proceed searching.

struct trieNode
{
char currentChar;
int endWord;
int endNode;
Vector<trieNode *> childNodes;
};

Initially it will have a dummy Node with possible first letters of the paragraph.
2nd Level will have two letter words

endWord denote the end of a word in the paragraph.
endNode will denote end of the tree depth in this branch.

O(log n) for one search and O(n log n ) for all the words search

- yogesh February 12, 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