Amazon Interview Question for Software Engineer / Developers


Country: India
Interview Type: Phone Interview




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

I am sure you can achieve this by using sed or awk in a more elegant way but here are the other ways

grep "^ERROR" <YOUR LOG FILE NAME"
cut -d " " -f1 <YOUR LOG FILE NAME> | grep "ERROR"

The "cut" command assumes that your log file delimiter is a space.

- Arun Manivannan August 28, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Good!
+1.

- Anonymous August 28, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Honestly, I think this is the answer they are looking for

- airfang613 August 29, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

As word to match is very small ( ERROR ), so using KMP wont give any significant performance improvement. I think it can be done easily using brute force ( match each character one by one until we find '\n' or word matches, then continue for next line in similar manner ).

- Cerberuz August 28, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Duplicate of the other question that you posted. At the risk of being redundant, here is the possible answer


I am sure you can achieve this by using sed or awk in a more elegant way but here are the other ways

grep "^ERROR" <YOUR LOG FILE NAME"
cut -d " " -f1 <YOUR LOG FILE NAME> | grep "ERROR"

The "cut" command assumes that your log file delimiter is a space.

- Arun Manivannan August 28, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think the interviewer expects implementation rather then direct use of library/language/shell function.

- Cerberuz August 28, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Oh sorry about that. Since the question didn't have any references to implementation, I thought the usage of a tool is acceptable.

Like you said, we could use brute force. Just that instead of checking for \n, we could stop soon after we reach the character length of search string or 5 in case of "ERROR"

- Arun Manivannan August 28, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

No need to be sorry about that, nice quick solution though, who knows interviewer might also get impressed seeing your scripting skills :)

- Cerberuz August 28, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

No, the interviewer expects using tools. Go read some blogs about amazon interviews.

- Anonymous August 28, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

What if the log is getting updated frequently...

- Saub August 28, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

You could do a

tail -f <LOG FILE NAME> | grep "^ERROR"

but then this wouldn't handle log file roll over.

- Arun Manivannan August 29, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

i am getting a error while running the above mentioned script by arun manivannan

- ghost September 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i am getting a error while running the above mentioned script by arun manivannan the error is :
syntax error near token |

- ghost September 16, 2012 | 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