Amazon Interview Question for Applications Developers


Country: India
Interview Type: Phone Interview




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

sed -n '/STARTDATE/,/ENDDATE/p' log.txt | grep -c ERROR

- Daya May 14, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This would be off by 1 (1 less):
i.e:

07-01-1992
ERROR
07-02-1992
ERROR

Now this will only count the first error if we take it from 07-01-1992 to 07-02-1992, not only that, it will fail if there is no error that start / end date.

- Mo Lam May 15, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

It will work only if you take start date and end date as exact given in the file.

- lakshitarora26 June 05, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 2 vote

Use date as the key. Use a cumulative array A that counts the number of errors seen up to (and including) a given date.

Given dates di and dj where di<=dj, the number of errors between those dates is simply
: A[dj]-A[di-1]

- Murali Mohan May 18, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

If we want to maintain a dynamic set of records, a still better approach would be to use a balanced BST. The BST would have date as the 'key' field and should be augmented with a 'errorCount' field that maintains the count of errors seen on a given date.

1. As the input file is scanned, insert/update errorCount field of the appropriate key in the BST
2. To find the errorCount in a given range, use a modified version of rank() operation that adds up the errorCount fields is the subtrees.

- Murali Mohan May 20, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 votes

3. Error count in the range would be rank(endDate) - rank(startDate)

- Murali Mohan May 20, 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