May 2009 - May 2017 论坛八周年-你的足迹,我的骄傲


一亩三分地论坛

 找回密码
 获取更多干活,快来注册

一亩三分地官方iOS手机应用下载
查看: 2773|回复: 1
收起左侧

Amazon OA新题 用户-好友-好友推荐的课程 code

[复制链接] |试试Instant~ |关注本帖
laonong15 发表于 2016-2-24 04:53:48 | 显示全部楼层 |阅读模式

2016(1-3月) 码农类 本科 全职@Amazon - Other - 技术电面 |Other其他

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看,没有帐号?获取更多干活,快来注册

x
the original  link  is :
http://www.1point3acres.com/bbs/ ... p;page=1#pid2230193
. more info on 1point3acres.com
just  write the code  by myself,  but  didnt test it :.1point3acres缃
. 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴
package Amazoninterview; 鏉ユ簮涓浜.涓夊垎鍦拌鍧.

import java.util.Collections;. Waral 鍗氬鏈夋洿澶氭枃绔,
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;.鏈枃鍘熷垱鑷1point3acres璁哄潧
import java.util.Iterator;
import java.util.LinkedHashMap;.鏈枃鍘熷垱鑷1point3acres璁哄潧
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/*
* 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 . 鍥磋鎴戜滑@1point 3 acres
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,  
.鏈枃鍘熷垱鑷1point3acres璁哄潧
t's O(n) Space  because n is the number of courses selected in total by all your friends.
A  it would be O(k*p) where k is the number of friends and p is the number of courses a friend selects
*/
public class Recommender {

        public static void main(String[] args) {
               
        }
        public static Map<String,Integer> getRecommedations(String userId){
                List<String> friends = getFriendsListForUser(userId);
                HashSet<String> myCourses = getCoursesForUser( userId);
                if(friends ==null || friends.size() ==0 )
                        return null;
                if(myCourses == null)
                        myCourses = new HashSet<String>();
                HashMap<String,Integer> recommendMap = new HashMap<String,Integer>();
                for(String friend:friends){
                        HashSet<String> friendCourseList = getCoursesForUser( friend);
                        for(String course:friendCourseList){
                                if(myCourses.contains(course))
                                        continue;
                                if(recommendMap.get(course)!=null){. from: 1point3acres.com/bbs
                                        recommendMap.put(course, recommendMap.get(course)+1);
                                }
                                else{. more info on 1point3acres.com
                                        recommendMap.put(course,1);
                                }
                        }.鐣欏璁哄潧-涓浜-涓夊垎鍦
                }
                if(recommendMap !=null && recommendMap.size() >0)
                        return sortByValue(recommendMap);
                return null;
        }
       
        public static Map sortByValue(Map unsortMap) {         . 鍥磋鎴戜滑@1point 3 acres
                List list = new LinkedList(unsortMap.entrySet()); 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
         . From 1point 3acres bbs
                Collections.sort(list, new Comparator() {
                        public int compare(Object o1, Object o2) {
                                return ((Comparable) ((Map.Entry) (o1)).getValue()).鏈枃鍘熷垱鑷1point3acres璁哄潧
                                                        .compareTo(((Map.Entry) (o2)).getValue());
                        }. visit 1point3acres.com for more.
                });.鏈枃鍘熷垱鑷1point3acres璁哄潧
         
                Map sortedMap = new LinkedHashMap();
                for (Iterator it = list.iterator(); it.hasNext();) {. 1point 3acres 璁哄潧
                        Map.Entry entry = (Map.Entry) it.next();
                        sortedMap.put(entry.getKey(), entry.getValue());
                }
                return sortedMap;. visit 1point3acres.com for more.
        }
       
        //giving function . from: 1point3acres.com/bbs
        -google 1point3acres
        public static  List<String> getFriendsListForUser(String userId){
                return null;        . 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴
        }
        public static HashSet<String>getCoursesForUser(String userId){
                return null;
        }
}

hopfully  it helps


. 鍥磋鎴戜滑@1point 3 acres
daykills 发表于 2016-2-24 09:43:23 | 显示全部楼层
关注一亩三分地公众号:
Warald_一亩三分地
我面的也是这题...你后来需要搞个半小时的电话面谈吗?
回复 支持 反对

使用道具 举报

本版积分规则

关闭

一亩三分地推荐上一条 /5 下一条

手机版|小黑屋|一亩三分地论坛声明 ( 沪ICP备11015994号 )

custom counter

GMT+8, 2017-5-27 16:38

Powered by Discuz! X3

© 2001-2013 Comsenz Inc. Design By HUXTeam

快速回复 返回顶部 返回列表