Amazon OA Interview Question: Stuff Your Friends Are Buying

21 Views
No Comments

Amazon is releasing a feature called "Stuff Your Friends Are Buying".

Implement a function that returns stuff that a person’s friends are buying that the person has not bought, in order of popularity.

Returns a list of purchases of the person. If purchased multiple times, it will be in the list multiple times.

List<Purchase> getPurchases(Person person);

Returns a list of friends of the person.

List<Person> getFriends(Person person);

This problem asks you to recommend items that a person's friends are buying, excluding anything the person has already purchased, and to rank the results by popularity. A typical solution is to use a hash set for the person's purchases, then traverse all friends' purchase lists and count item frequencies with a hash map. Because purchases may appear multiple times, frequency counting matters. After filtering out items already bought by the person, sort by count and return the ranked list.

END
 0