Amazon Interview Question for Software Developers


Country: United States




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

Use a queue, when queue.size > 3, empty the queue for the result

- ian April 12, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Let's call the period P and the threshold T

1. Let's suppose we have an event listener that listens for incoming events and we have a function to handle the call, we can use a queue or either just a plain int for counting the number of events within a timewindow P:

int numEvents = 0;

function eventHandler {
numEvents ++;

if (numEvents >= T) {
return true
}
return false
}

2. After that we build a scheduler that will run every P units of time (milliseconds, seconds etc...) the scheduler will run a task that resets the counter to 0

class ResetTask extends TimerTask {
    public void run() {
	numEvents = 0;
    }
}

Timer timer = new Timer();
timer.schedule(new ResetTask(), 0, T); // make sure to conver to proper unit : milis, seconds, etc...

This way you can know for any given timestamp X if the threshold has been surpassed

- guilhebl April 18, 2018 | 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