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, KiwiMy 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:
friends of friends?Leadership Prnciples:
Verdict: Selected