Amazon Interview Question for Production Engineers






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

Why is this filed under "Linux Kernel"?

- LOLer July 15, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Good Qn - may be because author thinks that grep and awk are under linux kernel ??? :-)

- danny March 12, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

The following SQL query would do the required task:
select stud_name from table where mark1=(select max(mark1) from table) or mark2=(select max(mark2) from table) or mark3=(select max(mark3) from table);

- idea July 14, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think she mentioned a file not a database

- anonymous July 15, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

even it is a DB question, your answer is not correct.
1. You cannot assume there are only 3 subjects( in your SQL, you used mark1,2,3 for 3 subjects)
2. In each subject, there might be more than one highest scores. so you might not want to use the symbol '='


My answer for the SQL will be:

select * from table
where (subject, score)
in
(
select subject , max(score)
from table
group by subject )

The sub-query lists out : the data set of subject and max(score) for each subject.
then use the result combination feeding the main query for the record matching highest score in each subjects

- Zhijing Chen April 05, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

If she posts in the correct location, then check "swoveck " 's answer

- Zhijing Chen April 05, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I am calling this table performance. Below query should work.

Select P1.* from PERFORMANCE P1, (SELECT MAX(MARK) D1, SUBJECT D2 FROM PERFORMANCE GROUP BY SUBJECT) P2 where P1.MARK = P2.D1 and P1.SUBJECT = P2.D2

- Amit July 14, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

sort the file using 'sort -rk 2,3 filename' and then take the first line from each
subject.

- Sumanth July 16, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

it seems the rest wrote crap. you anwered smartly. adding to your answer to pick the last two
sort -rk 2, 3|head -n2
and this should give the required answer. done!

- LLOLer August 05, 2009 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Question states "get the student from each subject who secured the highest mark". This solution will give us the student (or 2 students) who secured the highest mark from the subject that is first in reverse alphabetical order. Also reversing the order (-r option) makes sense only if marks are numerical and the highest mark is better. In US however, marks are represented by the alphabetical letters like A,B,C,D,E and A (lowest) is the best. I think that correct answer could be something like this:

cat filename | sort -k 2,3 | awk '{if($2 != prev) {print; prev = $2;}}'

- swoveck August 08, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

How does this grep the topscorer in each subject after the sort is complete?

- Zebra September 07, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

swoveck is basically right, except when sorting, he missed -r. Good job swoveck

- Zhijing Chen April 05, 2013 | 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