Yahoo Interview Question for Software Engineer / Developers






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

I think the interviewer is asking for the UNIX command wc.

- BXH September 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We start reading the file until eof is reached.
Every character we read increases the number of characters by 1.
Every new line character increases the number of lines by 1.
And every new line and set of space characters increases the number of words by 1.
So by using just one read character command in c,c++ or java we can count all of them.

- cac September 18, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This topic also appears in a Google interview.
The tricky point is to handle multiple spaces between two words.

- jimmyzzxhlh September 20, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

If we encounter a space, just increase the word-count by 1 unless the previous character was also a space

- chandransuraj February 08, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

<pre lang="c" line="1" title="CodeMonkey62191" class="run-this">#include<stdio.h>
main(){
FILE *fp;
fp = fopen("input.txt","r");
char read[1000];
int lines=0,words=0,characters=0;
while(fgets(read,1000,fp)){
lines++;
int i=0;
while(read[i]){
if(read[i++]==' ')
words++;
else
characters++;
}
}
printf("%d %d %d\n",lines,words+1,characters);
getchar();
}
</pre><pre title="CodeMonkey62191" input="yes">
</pre>

- Anonymous October 27, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

While computing words one also has to take care of text separators like , - /t etc

- Hjindal December 30, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

While computing words one also has to take care of text separators like , - /t etc

- Hjindal December 30, 2010 | 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