回复: 18
跳转到指定楼层
上一主题 下一主题
收起左侧

挨骂总OA面经

全局:

2017(4-6月) 码农类General 本科 全职@amazon - Other - 在线笔试  | | Other | 其他

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

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
遇到了一道没有做过的题,用了union find现做出来的:(场景叙述做了处理)
给出一串Pair, 每个pair说明两个人互为朋友,[A,B] 说明A和B是朋友,[C,B] 说明C和B是朋友,{D,E}说明E和D是朋友。
找出人数最大的朋友圈,如果两个朋友圈人数相等,返回有着字典顺序最小朋友的那个圈。

代码:
import java.util.*;

public class FriendCircle {
    public static void main(String[] args) {

        assert true == Arrays.equals(
                new String[] {"friend3", "friend4", "friend5"}
                , new FriendFriendCircle().findLargestFriendCircle(new String[][]{
                        {"friend1", "friend2"},
                        {"friend3", "friend4"},
                        {"friend4", "friend5"},
                }));

        assert true == Arrays.equals(
                new String[] {"friend
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
String[] res = new String[max];
        for(Map.Entry<String, String> ent : unionKeys.entrySet()) {
            if(ent.getValue().equals(maxKey)) {
                res[--max] = ent.getKey();
            }
        }

        Arrays.sort(res);
        System.out.println(Arrays.toString(res));

        return res;
    }


}








补充内容 (2017-6-13 14:14):
还有请问:A家OA没过,有无冷冻期,能不能继续投?谢谢

评分

参与人数 2大米 +33 收起 理由
富民文 + 3 感谢分享!
夏虫不知雪花 + 30

查看全部评分


上一篇:微软电面I II
下一篇:口袋宝石OA 5月底新题
推荐
iceman 2017-10-29 12:28:00 | 只看该作者
全局:
顶12楼 - local run 加了这段就能过1234 case了:
        /************************************************************/
        // critical: get final root for each person
        // need this to ensure all people are mapped to "real" root
        for(Map.Entry<String, String> ent : pre.entrySet()) {
                String curVal = ent.getValue();
                String curKey = ent.getKey();
                if (root.containsKey(curVal)) {
                        String finalRoot = find(root, curVal);
                        pre.put(curKey, finalRoot);
                }
        }
        /************************************************************/
回复

使用道具 举报

推荐
wwei17 2017-9-22 04:21:00 | 只看该作者
全局:
你的union find的算法不太对 我跑了一下case {{“1”,“2”}, {“3”,“4”},{ “1“, ”3”}}, 其结果应该为 1234, 但是你的算法只得到123, 原因出在这里:
        for(Map.Entry<String, String> ent : unionKeys.entrySet()) {-google 1point3acres
            counts.put(ent.getValue(), counts.getOrDefault(ent.getValue(), 0) + 1);
        }
是不能直接加的 要重复寻找unionkeys的unionkeys的unionkeys的。。。直到key不变为止 具体算法见 https://www.cs.princeton.edu/~rs/AlgsDS07/01UnionFind.pdf
回复

使用道具 举报

全局:
请问什么叫做字典顺序最小的?每个朋友圈是一个字符串数组,对于字符串数组如何比较字典顺序?
回复

使用道具 举报

🔗
cawe 2017-6-15 06:10:35 | 只看该作者
全局:
oa没过似乎没有冷冻期
回复

使用道具 举报

🔗
 楼主| reddatecookies 2017-6-16 13:33:04 | 只看该作者
全局:
cawe 发表于 2017-6-15 06:10
oa没过似乎没有冷冻期

感谢经验!
回复

使用道具 举报

🔗
Tomyxue 2017-7-7 14:29:43 | 只看该作者
全局:
楼主,方便透露一下OA的结果怎么样,现在什么状态了吗?谢谢
回复

使用道具 举报

🔗
uscgaopeng 2017-7-7 22:01:53 | 只看该作者
全局:
我最近也投了亚麻,想跟着楼上问一下啊!
回复

使用道具 举报

🔗
supman 2017-7-7 22:34:09 | 只看该作者
全局:
。。。这个。。这个。。。哥们。。咱好好说话行吗
回复

使用道具 举报

🔗
dniny 2017-7-9 01:09:25 | 只看该作者
全局:
请问楼主,OA 可选的coding language 真的只有c++ 和 java 么?
回复

使用道具 举报

🔗
lulu_0386 2017-7-9 09:26:14 | 只看该作者
全局:
突然明白了是亚麻。。。
回复

使用道具 举报

🔗
Andrew007 2017-9-10 00:55:46 | 只看该作者
全局:
感觉挺复杂的啊,OA这么短时间能搞的定不? 感谢分享。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

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