📣 VIP通行证夏日特惠 限时立减$68
回复: 11
跳转到指定楼层
上一主题 下一主题
收起左侧

Google Coaching Hangouts

全局:

2016(4-6月) 码农类General 硕士 全职@google - Other - 技术电面  | | Other | 应届毕业生

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

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

x
您好!
本帖隐藏的内容需要积分高于 1 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 1 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies



祝大家offer多多!


评分

参与人数 1大米 +70 收起 理由
DamienPooh + 70

查看全部评分


上一篇:epic 面经
下一篇:Liveramp OA面经

本帖被以下淘专辑推荐:

推荐
airwindow 2015-10-13 23:14:18 | 只看该作者
全局:
不使用HashSet, space complexity为 O(1)的solution。
Main idea: set the visited elements equal to 0.
  1. static private boolean checkCircularArray2(int[] nums) {
  2.                 if (nums == null) {
  3.                         throw new IllegalArgumentException("nums's reference is null");
  4.                 }
  5.                 int i = 0;
  6.                 boolean isStart = true;
  7.                 int reachedCount = 0;
  8.                 /*
  9.                 cause we start from nums[0], we should use a "isStart" flag
  10.                 to distinguish between it is the first start  or  it was reached.
  11.                 */
  12.                 while (nums[(i + nums[i]) % nums.length] != 0 || isStart) {
  13.                         int next = (i + nums[i]) % nums.length;
  14.                         if (!isStart) {
  15.                                 /*
  16.                                  * no need to worry (nums[i] = 0) in initial input.
  17.                                  * the pointer should stop at in both cases.
  18.                                  * */
  19.                                 nums[i] = 0;
  20.                         } else {
  21.                                 isStart = false;
  22.                         }
  23.                         i = next;
  24.                         reachedCount++;
  25.                 }
  26.                 return reachedCount == nums.length;
  27.         }
复制代码
回复

使用道具 举报

推荐
airwindow 2015-10-13 22:47:56 | 只看该作者
全局:
以下是我的愚见哈, 不做space优化的solution。
  1. static private boolean checkCircularArray(int[] nums) {
  2.                 if (nums == null)
  3.                         throw new IllegalArgumentException("nums's reference is null");
  4.                 int reachedCount = 0;
  5.                 HashSet<Integer> visited = new HashSet<Integer> ();
  6.                 int i = 0;
  7.                 while (!visited.contains(i + nums[i])) {
  8.                         visited.add(i + nums[i]);
  9.                         i = (i + nums[i]) % nums.length;
  10.                         reachedCount++;
  11.                 }
  12.                 return reachedCount == nums.length;
  13.         }
复制代码
Test cases:
testcases:
null -> exception;
{} //whether the empty array should be counted as CircularArray, we should discuss with interviewer
{1} -> false;
{2, -1, 1} -> false;
{1, 1, 1} -> true;
{2, -1, -1} -> true;
回复

使用道具 举报

推荐
tangvictor 2015-10-16 01:33:15 | 只看该作者
全局:
Python版代码,如有错误请指出。
  1. def circular(A):
  2.         # corner case
  3.         if A == None or len(A) == 0:
  4.                 return False

  5.         cur = 0
  6.         n = len(A)
  7.         count = 0

  8.         while True:
  9.                 if A[cur] == 0:
  10.                         break

  11.                 next =  (cur + A[cur]) % n
  12.                 A[cur] = 0
  13.                 count += 1
  14.                 cur = next       

  15.         return count == n
复制代码
回复

使用道具 举报

🔗
hyliu0000 2015-10-13 22:22:59 | 只看该作者
全局:
long sum(index) = (0 + nums.length - 1) * nums.length / 2 , 然后看sum是否会减到0.
回复

使用道具 举报

🔗
 楼主| lqzgz 2015-10-15 09:09:07 | 只看该作者
全局:
hyliu0000 发表于 2015-10-13 22:22
long sum(index) = (0 + nums.length - 1) * nums.length / 2 , 然后看sum是否会减到0.

这么做应该不对,[1, 4, 1]也是circular array
回复

使用道具 举报

🔗
 楼主| lqzgz 2015-10-15 09:09:45 | 只看该作者
全局:
airwindow 发表于 2015-10-13 22:47
以下是我的愚见哈, 不做space优化的solution。Test cases:
testcases:
null -> exception;

[1]是circular array
回复

使用道具 举报

🔗
hj867955629 2015-10-15 23:20:59 | 只看该作者
全局:
lqzgz 发表于 2015-10-15 09:09
这么做应该不对,[1, 4, 1]也是circular array

加个对数组长度取余,另外index是数组下标加数组value,应该可以
回复

使用道具 举报

🔗
@南岸的风 2015-10-21 01:25:03 | 只看该作者
全局:
lqzgz 发表于 2015-10-15 09:09
这么做应该不对,[1, 4, 1]也是circular array

楼主可以解释一下为什么[1,4,1]是circular array吗?thanks!
回复

使用道具 举报

🔗
 楼主| lqzgz 2015-10-21 07:12:52 | 只看该作者
全局:
@南岸的风 发表于 2015-10-21 01:25
楼主可以解释一下为什么[1,4,1]是circular array吗?thanks!

array[1] = 4; (1 + 4) % 3 = 2; 就是说这个移动是个loop
回复

使用道具 举报

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

本版积分规则

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