高级农民
- 积分
- 2426
- 大米
- 颗
- 鳄梨
- 个
- 水井
- 尺
- 蓝莓
- 颗
- 萝卜
- 根
- 小米
- 粒
- 学分
- 个
- 注册时间
- 2015-3-12
- 最后登录
- 1970-1-1
|
Here is the possible solution :
1. Use a HashSet<String> courseSet and store all the courses made by the user
2. Keep one more HashMap<Course, Integer> recommendation
2. Get the list of Friends for the user
3. Iterate through the friends list and in that find the courses selected by the friend
4. If the course present in courseSet, omit else, put it in recommendation and increment it's count by 1.
5. After all the friends are evaluated. Sort the recommendation by it's value,
it's O(n) Space because n is the number of courses selected in total by all your friends.
it would be O(k*p) where k is the number of friends and p is the number of courses a friend selects
The only thing confuse me is
do we need get all the friends' friends and add to friends list, It will depend on giving function " getFirendsListForuser" |
|