Google Interview Question for Senior Software Development Engineers


Country: United States
Interview Type: In-Person




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

1) calculate absolute times when a task get's added
2) push it into a priority queue with smallest absolute on top (binary heap)
3) have a runner that polls the queue once in a time interval (e.g. second) and checks if top task is to be executed, pop items from the heap that need to be executed.
4) now, the question is, how long does the run take? can I execute it synchronously or will this delay the scheduler? I could as well span into a thread pool to call run there.

a more sophisticated edge case is, if two items receive the same absolute time, is it required to maintain order of insertion when running? Might be relevant in some use cases. The mentioned edge case, is obvious. at 5 task b runs, at 10 task a runs.

runtime and space complexity is obvious.

- Chris December 08, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Is there a saviour ;) with a concrete implementation in Java along with handling the edge cases ?

- lks December 08, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@ChrisK. If the priority queue is using the absolute time when a task get's added, then, how would B5 run before A10? B2 is added later than A10. Maybe the time the priority queue is using should be the absolute time when the task should be executed?

- Alex December 08, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@Alex: of course, calculate the absolute time when the task should be run. this is calculated when a task get's added.

- Chris December 09, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@ChrisK. Cool! I just misunderstood "calculate absolute times when a task get's added" as "calculate absolute times equal to the time when a task gets added".

- Alex December 09, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can someone please implement this in Java ?

- lks December 09, 2017 | 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