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

重发LiveRamp的OA,有原题截图,free response好坑//非故意重发,只是想大家看到原题

本楼:
全局:
马克下!
回复

使用道具 举报

🔗
 楼主| 嘟嘟要一直努力 2015-10-1 10:08:38 | 只看该作者
全局:
天墨 发表于 2015-10-1 05:57
感谢楼主分享。。感觉它家面试的bar还是很高的。。。~~~~(>_

是嘛?其实我觉得我答得都很水啊,倒是听说他家不怎么招人是真的。等我二面之后争取再来跟进一些吧~~~
回复

使用道具 举报

🔗
 楼主| 嘟嘟要一直努力 2015-10-1 10:12:02 | 只看该作者
全局:
rhett.lhy 发表于 2015-10-1 04:33
这题可以用并查集来做吧?每次新来一个A=k的时候,把k插入到当前排好序的叶子当中,然后看左右邻居是不是在 ...

可是感觉UF的话memory或者runtime会不符合要求啊?sry我可能没截上,这两个都有要求限制,好像是O(N)我记得
回复

使用道具 举报

🔗
rhett.lhy 2015-10-1 11:59:49 | 只看该作者
全局:
Laurinda93 发表于 2015-10-1 10:12
可是感觉UF的话memory或者runtime会不符合要求啊?sry我可能没截上,这两个都有要求限制,好像是O(N)我记 ...

并查集的话总的时间复杂度是O(K log*K+ log K log*K) = O(K log * K), log*k (log star k) 基本上可以认为是一个constant,所以总时间复杂度约等于O(N).

lz帖的第一个implementation的复杂度是O(XD)的。

补充内容 (2015-10-1 12:08):
写错了……我想说的是disjoint set的复杂度是O(N logN log*N) ~ O(N logN), N是总共有多少个leaf。我不觉得这题能有O(N)的算法吧……
回复

使用道具 举报

🔗
rhett.lhy 2015-10-1 12:09:12 | 只看该作者
全局:
Laurinda93 发表于 2015-10-1 10:12
可是感觉UF的话memory或者runtime会不符合要求啊?sry我可能没截上,这两个都有要求限制,好像是O(N)我记 ...

我上一个回复写错了……我想说的是disjoint set的复杂度是O(N logN log*N) ~ O(N logN), N是总共有多少个leaf。我不觉得这题能有O(N)的算法吧……

第一个N是process所有的leaf,logN是找当前这个leaf的左边和右边最近的leaf,log*N是disjoint set操作。

补充内容 (2015-10-1 12:12):
时间复杂度是O(N logN log*N),空间复杂度是O(min{N, X})。所以肯定是比lz贴的时间复杂度O(XD)空间复杂度O(X)的solution要好的,如果那个解法符合要求的话,并查集肯定也符合要求吧……
回复

使用道具 举报

🔗
tldxk 2015-10-2 07:32:34 | 只看该作者
全局:
lz能在墙外网盘再放一遍吗?Google Drive公开链接/Dropbox啥的。。下了百度速度太慢。。。一下午都没下下来。。。
回复

使用道具 举报

🔗
rhett.lhy 2015-10-2 07:46:17 | 只看该作者
全局:
O(N logN log*N) implementation
  1.    
  2. public static int frogJump(int[] arr, int X, int D) {

  3.         class DisjointSet {

  4.             private java.util.concurrent.ConcurrentSkipListMap<Integer, Integer> parent;

  5.             public DisjointSet() {
  6.                 parent = new java.util.concurrent.ConcurrentSkipListMap<>();
  7.             }

  8.             public boolean check(int x, int y) {
  9.                 return findRoot(x) != -1 && findRoot(x) == findRoot(y);
  10.             }

  11.             public void addLeaf(int x) {
  12.                 parent.put(x, x);
  13.                 if (0 < x && x < X) {
  14.                     int other = parent.lowerKey(x);
  15.                     if (x - other <= D) {
  16.                         merge(x, other);
  17.                     }
  18.                     other = parent.higherKey(x);
  19.                     if (other - x <= D) {
  20.                         merge(x, other);
  21.                     }
  22.                 }
  23.             }

  24.             public int findRoot(int x) {
  25.                 if (parent.get(x) == null) {
  26.                     return -1;
  27.                 }
  28.                 if (parent.get(x) == x) {
  29.                     return x;
  30.                 }
  31.                 int ans = findRoot(parent.get(x));
  32.                 parent.put(x, ans);
  33.                 return ans;
  34.             }

  35.             public void merge(int x, int y) {
  36.                 int rx = findRoot(x);
  37.                 int ry = findRoot(y);
  38.                 parent.put(ry, rx);
  39.             }
  40.         }
  41.         // end of disjoint set definition

  42.         if (X <= D) {
  43.             return 0;
  44.         }

  45.         DisjointSet ds = new DisjointSet();
  46.         ds.addLeaf(0);
  47.         ds.addLeaf(X);

  48.         for (int i=0; i<arr.length; i++) {
  49.             ds.addLeaf(arr[i]);
  50.             if (ds.check(0, X)) {
  51.                 return i;
  52.             }
  53.         }
  54.         return -1;
  55.     }
复制代码

补充内容 (2015-10-2 07:50):
再稍微优化一下,不处理重复的leaf的话,就是O(N logK log*K)了,K = min{X, N}
回复

使用道具 举报

🔗
rhett.lhy 2015-10-2 07:54:33 | 只看该作者
全局:
稍微改了下处理重复叶子的问题。现在应该是O(N logK log*K)了,K = min{X, N}
  1.    
  2. public static int frogJump(int[] arr, int X, int D) {

  3.         class DisjointSet {

  4.             private java.util.concurrent.ConcurrentSkipListMap<Integer, Integer> parent;

  5.             public DisjointSet() {
  6.                 parent = new java.util.concurrent.ConcurrentSkipListMap<>();
  7.             }

  8.             public boolean check(int x, int y) {
  9.                 return findRoot(x) != -1 && findRoot(x) == findRoot(y);
  10.             }

  11.             public boolean addLeaf(int x) {
  12.                 if (parent.containsKey(x)) {
  13.                     return false;
  14.                 }
  15.                 parent.put(x, x);
  16.                 if (0 < x && x < X) {
  17.                     int other = parent.lowerKey(x);
  18.                     if (x - other <= D) {
  19.                         merge(x, other);
  20.                     }
  21.                     other = parent.higherKey(x);
  22.                     if (other - x <= D) {
  23.                         merge(x, other);
  24.                     }
  25.                 }
  26.                 return true;
  27.             }

  28.             public int findRoot(int x) {
  29.                 if (parent.get(x) == null) {
  30.                     return -1;
  31.                 }
  32.                 if (parent.get(x) == x) {
  33.                     return x;
  34.                 }
  35.                 int ans = findRoot(parent.get(x));
  36.                 parent.put(x, ans);
  37.                 return ans;
  38.             }

  39.             public void merge(int x, int y) {
  40.                 int rx = findRoot(x);
  41.                 int ry = findRoot(y);
  42.                 parent.put(ry, rx);
  43.             }
  44.         }
  45.         // end of disjoint set definition

  46.         if (X <= D) {
  47.             return 0;
  48.         }

  49.         DisjointSet ds = new DisjointSet();
  50.         ds.addLeaf(0);
  51.         ds.addLeaf(X);

  52.         for (int i=0; i<arr.length; i++) {
  53.             if (ds.addLeaf(arr[i]) && ds.check(0, X)) {
  54.                 return i;
  55.             }
  56.         }
  57.         return -1;
  58.     }
复制代码
回复

使用道具 举报

🔗
 楼主| 嘟嘟要一直努力 2015-10-2 10:40:58 | 只看该作者
全局:
tldxk 发表于 2015-10-2 07:32
lz能在墙外网盘再放一遍吗?Google Drive公开链接/Dropbox啥的。。下了百度速度太慢。。。一下午都没下下来 ...

这两天好多面试忙得有点晕,不出意外地话 我周六做完一个OA,应该会再来写个面经,到时候还要传不少东西,我到时候一起OK吗?
回复

使用道具 举报

🔗
vnana_lala 2015-12-6 03:53:40 | 只看该作者
全局:
谢谢楼主整理啊,今天申请就给发了OA,还有好多题目没刷。。。
回复

使用道具 举报

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

本版积分规则

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