Amazon Interview Question for Software Engineer / Developers


Country: CANADA
Interview Type: In-Person




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

I guess the data structure stack fits this requirement well.

- kr.neerav April 08, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Like kr.neerav said, a Stack would be a good fit I suppose, so long as you decide that you'll keep N items, and make sure that N doesn't grow beyond N. Specifically, when a product is accessed, you would add it to the stack, and then remove the last element to keep the size in check.

A database is really what seems appropriate. Have a last accessed time for each product, and then you can quickly query that information.

What would be bad with the stack approach, is that you'd blow it out really fast. In other words, if you are hitting this millions of times per second, you'll probably end up thrashing the mutex.

So, if you had a big enough min-heap, you could store everything in that, with a HashMap as a lookup data structure, and use the time-accessed as your heap comparison. Then just pull off the N min values when you need the information.

Lots of approaches you can talk about here, and the tradeoffs between them all. Database would utilize existing data structures and capabilities. The information would already be cached from the database or disk since they were presented to the user, so data locality is good.

- rotinom April 08, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

How is a stack a good solution? Isn't a Stack LIFO? If we are adding the most recently accessed product on top of the stack, how can we remove the least accessed element from the bottom of the stack in O(1) time? What happens if the customer is accessing a product that is already in the stack?(do we add the product again?). I must be missing some detail

- Meh ... April 09, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I guess LRU is the solution....

- Victor April 09, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Yes stack is not good idea. We might add lot of duplicates. So hash shud be part of the solution. I think its just similar to LRU except that its most recently used instead of LRU. but same data structure would do

- im.code.warrior April 10, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Say, Rest api is like /user/recent_items?userid=[id]

I would keep the hash table of items that were checked out by all users.
Due to the memory constraint, this hash table only keeps certain number of items. To make sure the hash table would keep most recently check items by users, I would like the LRU list to keep the item ids.

This will make sure only most recently view items would stay in the cache.

- hankm2004 April 10, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use Queue instead of stack. As it works on FIFO rule .

- xyz April 26, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Precisely why a stack is a better fit. You want LIFO, not FIFO. The most recent item viewed should be the first item displayed.

- DTSFinancial April 28, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Neither queue nor stacks serves the purpose..because we want to retrieve the elements in a LIFO manner and have to delete the elements in a FIFO manner..so a new data structure to handle this should be implemented..

- sarat April 29, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How about doubly link list. We can take the fetched node to head and in case of new add of page, the last node can be deleted

- rahul May 29, 2014 | 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