Amazon Interview Question for Software Engineer / Developers


Team: AWS
Country: United States
Interview Type: Phone Interview




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

int main()
{
ifstream fin;
fin.open("a.in");
 int flag=0,w=0;
char ch;
    while(fin.get(ch)&&ch!=EOF)
    {
        cout<<ch;
        if(ch==' '||ch=='\t'||ch=='\n')
        flag=0;
        else if(flag==0)
        {flag=1;
        w++;
        }
    }
    cout<<w;

}

- aakash01 December 26, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think we can use the string tokenizer function with space (" ") as one parameter .Then we can put a counter after the strtok and we can know the number of words.

- psaikaushik December 24, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

corner case: handle one long word

- Anonymous December 25, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

One solution: read char by char, and count the "whitespaces". With this algo, amount of memory is not an issue.

- Anonymous December 25, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

We just can't count spaces because there can be multiple whitespaces between words, and there can other delimiters between words like comma, period, semi-colon etc.
So, one solution can be have a Finite State machine with may be like 2 states (READING_WORD, IN_DELIMITER) and calculate the state transition from IN_DELIMITER -> READING_WORD which should give number of words.

- Chethan December 29, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Could you please eloborate the solution

- Srishti January 19, 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