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

Square onsite面经

全局:

2016(4-6月) 码农类General 硕士 全职@square - 网上海投 - Onsite  | | Fail | 在职跳槽

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

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

x
地里Square的面经不多,来发一个1. Coding:他家高频的掉方块问题
2. Coding:
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
t booking website
5. Project

评分

参与人数 2大米 +40 收起 理由
cancerlk + 10 很有用的信息!
夏虫不知雪花 + 30

查看全部评分


上一篇:有没有人遇到过Amazon onsite结束以后再来一轮电面的?
下一篇:鸽了google面试会进小黑屋吗
🔗
sisolcode 2016-7-26 11:26:24 | 只看该作者
全局:
請問第一題你能說說大致的思路嗎? 最近要電面,看到滿多人電話也接到這題
回复

使用道具 举报

🔗
 楼主| zhubobo 2016-7-27 12:30:10 | 只看该作者
全局:
sisolcode 发表于 2016-7-26 11:26
請問第一題你能說說大致的思路嗎? 最近要電面,看到滿多人電話也接到這題

贴一下我的代码
public class AddSquare {
        private static class Node {
                private float a;
                private float b;
                private float h;
                public Node(float a, float b, float h) {
                        this.a = a;
                        this.b = b;
                        this.h = h;
                }
        }
        private TreeSet<Node> treeset;
        private float maxHeight;
       
        public AddSquare() {
                treeset = new TreeSet<Node>(new Comparator<Node>() {
                        public int compare(Node x, Node y) {
                                float diff = x.a - y.a;
                                if (Math.abs(diff) < 1e-10) {
                                        return 0;
                                }
                                return x.a < y.a ? -1 : 1;
                        }
                });
                maxHeight = 0;
        }
       
        public void drop(float position, float size) {
                Node newnode = new Node(position, position + size, size);
                Node left = getLeftBound(newnode);
                Node right = getRightBound(newnode);
                if (left == null && right == null) {
                        treeset.add(newnode);
                        maxHeight = Math.max(maxHeight, size);
                        return;
                }
                float curMaxHeight = left.h;
                Node cur = left;
                while (cur != right) {
                        Node tmp = treeset.higher(cur);
                        curMaxHeight = Math.max(curMaxHeight, cur.h);
                        treeset.remove(cur);
                        cur = tmp;
                }
                curMaxHeight = Math.max(curMaxHeight, right.h);
                treeset.remove(right);
                if (left.a < newnode.a) {
                        treeset.add(new Node(left.a, newnode.a, left.h));
                }
                if (newnode.b < right.b) {
                        treeset.add(new Node(newnode.b, right.b, right.h));
                }
                treeset.add(new Node(newnode.a, newnode.b, size + curMaxHeight));
                maxHeight = Math.max(maxHeight, size + curMaxHeight);
        }
       
        public float getHeight() {
                return maxHeight;
        }
        private Node getLeftBound(Node n) {
                Node smaller = treeset.lower(n);
                if (smaller != null && overlap(smaller, n)) {
                        return smaller;
                }
                Node larger = treeset.ceiling(n);
                if (larger != null && overlap(larger, n)) {
                        return larger;
                }
                return null;
        }
       
        private Node getRightBound(Node n) {
                Node dummy = new Node(n.b, n.b, n.h);
                Node smaller = treeset.floor(dummy);
                if (smaller != null && overlap(smaller, n)) {
                        return smaller;
                }
                return null;
        }
       
        private boolean overlap(Node x, Node y) {
                return !greater(x.a, y.b) && !less(x.b, y.a);
        }
       
        private boolean greater(float x, float y) {
                return x - y > 1e-10;
        }
       
        private boolean less(float x, float y) {
                return x - y < -1e-10;
        }
        public static void main(String[] args) {
                // TODO Auto-generated method stub
                AddSquare test = new AddSquare();
                test.drop(1,4);
                System.out.println(test.getHeight());
                test.drop(3,3);
                System.out.println(test.getHeight());
                test.drop(-1,3);
                System.out.println(test.getHeight());
                test.drop(5.5f, 3);
                System.out.println(test.getHeight());
                test.drop(10, 5);
                System.out.println(test.getHeight());
                test.drop(-1, 6.5f);
                System.out.println(test.getHeight());
        }

}

评分

参与人数 1大米 +3 收起 理由
Rain + 3 感谢分享!

查看全部评分

回复

使用道具 举报

🔗
mdzzxswl 2016-8-3 11:42:27 | 只看该作者
全局:
是最近网投的吗~我上周网申了intern然后今天邮件说拒了面试都没给。。。是他们家bar不低还是自己太弱 泪目
回复

使用道具 举报

🔗
 楼主| zhubobo 2016-8-4 13:05:27 | 只看该作者
全局:
mdzzxswl 发表于 2016-8-3 11:42
是最近网投的吗~我上周网申了intern然后今天邮件说拒了面试都没给。。。是他们家bar不低还是自己太弱 泪目

不是网投的,是recruiter直接联系我的
回复

使用道具 举报

🔗
han4011 2017-3-3 14:47:42 | 只看该作者
全局:
Guava Fluentiterable class 是啥意思?
回复

使用道具 举报

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

本版积分规则

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