HackerRank - Amazon China Code Challenge
亞馬遜今年 Amazon China Code Challenge 的題目之一
藉由社交網路產生推薦課程清單
題目要求
推薦的課程要是 user 沒上過 的
社交網路朋友共同 上過愈多次的要排在愈前面
社交網路的定義是 三層以內 的直接朋友
Suppose you are an engineer on the Amazon Student team.
Your team wants to launch a new feature called “Courses Your Social Network have Attended,”
that lists all courses that your social network are taking, sorted by popularity.A social network is defined as all direct friends and all direct friends of direct friends.
People three levels deep are not part of the social circle, as illustrated below.The recommendation logic is based on the following rules:
- A user should only be recommended
a course that their social network have attended
but they have not attended- The recommendations priority is driven by
how many people have attended the same course –
if multiple people attended the same course,
it should be higher in the recommendations than
a course that only one person attended.You are provided two library functions to help you
getDirectFriendsForUser
– returns a list of customer IDs (strings that uniquely identify an Amazon user)
representing the direct friends of an Amazon usergetAttendedCoursesForUser
– returns a list of course IDs (strings that uniquely identify a course)
for an Amazon user ordered by attendance time
with newest course first in list
and oldest course last in listFor this evaluation,
please write a function that provides a ranked (high to low)
list of courses (course IDs) for a provided user.
|
|
我的解法
給大家參考
my solution here, FYI.: