Amazon Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

Can the oldest friend change in the case of current oldest friend gets removed from friend list,
If so,
need to maintain timestamp or some counter like # of friends along with list of friends.
Otherwise, it is oldest friend is like a primary key for a person, can be stored.

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

The oldest friend will be the 1st friend added unless it gets removed. So I think an "ID" and "Valid" column in relationship database will be able to get the answer, right? In Rails, it could look like this:

user.friends.find_by_valid(true) #it will return the 1st valid friends ordered by ID.

- samchen2009 February 01, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Adjacency list representation of the friendship graph is good enough for this problem. The first one in the list is your first friend, delete him then second guy comes to the front.

- Anonymous February 03, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Adjacency list representation of the friendship graph is good enough for this problem. The first one in the list is your first friend, delete him then second guy comes to the front.

- Anonymous February 03, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Adjacency list representation of the friendship graph is good enough for this problem. The first one in the list is your first friend, delete him then second guy comes to the front.

- Anonymous February 03, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Adjacency list representation of the friendship graph is good enough for this problem. The first one in the list is your first friend, delete him then second guy comes to the front.

- Anonymous February 03, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Adjacency list representation of the friendship graph is good enough for this problem. The first one in the list is your first friend, delete him then second guy comes to the front.

- Anonymous February 03, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Keep friends in

Nodes

in a

Graph

and have a property in the Node for when added. Then do a breadth-first-search to find a node which has the oldest date.

- adbhai.mtl February 05, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

we can use a graph representation. Now on a avg each user has around 200 friends(max is like 5k-10k). we can put them into a heap as the unfriend operation happens very rarely and find oldest will be happening frequently.
Solution lot depends on the conditions and the frequency of different operations and space constraints. That will be part of followup questions.

Another thing that can be done here is that we can have a doubly linkedlist of graph nodes based on order of time when the friend was added. this will optimize all get, delete and add operations but at cost of memory.

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

I think this can be implemented by constructing a min-heap. The heap property can consider friendship timestamp for sorting order while insertion. At any given time the root node will have the minimum timestamp value, and hence the oldest friend.

The deletion operation for min-heap will take care of popping up lowest timestamp (i.e. newer than oldest friend, but older than others) node in root position.

- Puneet October 17, 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