Amazon Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




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

Approach 1:
Use a circular linked list, for the first N calls keep adding items to the LL.
Maintain pointer to currently added element. From N+1th call see if the oldest item (currentElement.next) timestamp is less than current item – X. if it’s the case replace the timestamp and move the currentElement pointer to this element. If it’s not the case return false.
Time Complexity O(1)
Space Complexity O(N).
Approach 2:
If we take first call time as a reference (t0) then in idealistic case when events are generated with N/X frequency then function should return all true.
From this reference, suppose last event occur in interval t0 + (N/X)x, then if next occur after t0 + (N/X)x + N/X return true else false.
So we need to store interval of only last event, thus space complexity O(1)
Time Complexity O(1)

- iictarpit December 19, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

i think this method would also work......
if(time_elapsed_in_seconds%X==0 && counter<N)
return true;
else
return false;

- jkl December 22, 2012 | Flag
Comment hidden because of low score. Click to expand.
4
of 8 vote

Just return false everytime

- raj December 19, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Awesome..!! :-P

- decoder December 20, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yeah!! :)

- Kary December 22, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

please explain question in detail

- NoMind January 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. create a queue to hold the calls for last x seconds. and create a counter.
2. when the service is called:
if the queue is filled then remove the oldest call and if that has returned true then count--
if count < N then increment counter, add the call to the queue and return true
else add the call to queue and return false without incrementing counter

- cafebabe January 06, 2013 | 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