Amazon | SDE2 | Phone Screen | Product Recommendation
Anonymous User
3146

SDE2 | May, 2021 | EU

Coding question:

Problem: Product Recommendation based on most bought products by friends.

Given two APIs - one to get a list of friends and another one to get a list of someone's recent purchases, design an API which returns a list of x number of products purchased by most friends (popular purchases), order should be based on "ordered by most to least people in one's friends list". Make sure to include "one purchase per product per person" to not skew the results. What would be the time complexity of the solution?

Example:

Two most pupular products
 
A's friends - B, C, D
B's purchases - Apple, Apple, Apple, Kiwi, Cherry
C's purchases - Kiwi, Cherry
D's purchases - Cherry, Almonds

Output:  Cherry, Kiwi

My Approach: I used a List to get all friends and HashSet to get all unique products per friend and HashMap to store the count of products and sorted it based on value to return the final list (TreeMap can be used for the same). To get a list for friends of friends we can use BFS to get friends level wise.

Follow up:

  • What if we want to include the popular products of friends of friends?
  • Which approach would you follow?

Leadership Prnciples:

  1. Tell me about a time when you had a disagreement with your manager? How did you put across your point?
  2. Tell me about a time when you had little information about the task? How did you proceed? Was the project completed on time? How long did it take? What did you learn from that?
  3. Tell me about a time when new requirements were added by the customer just before the deadline? Did you implement them?

Verdict: Selected

Comments (1)