查看: 1635| 回复: 1
跳转到指定楼层
上一主题 下一主题
收起左侧

[找工就业] Google Singapore 電面

全局:

2019(4-6月)-CS本科+3个月-1年 | 网上海投|亚洲地区 码农类General全职@google

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

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

x
Google SG phone interview
date: 2019/June/11

Problem 1 get distance between X Y:

The string composed of X Y O, please return the closest distance between any pair of X and Y
e.g.
YOOOOOXOOOXOY
. 1point 3acres
X: 10
Y: 12
→ Output = 12 - 10 = 2

interviewer agree with this solution-baidu 1point3acres


  1.     def get_dist(str):
  2.         min_dist = float('inf')
  3.         is_X = None
  4.         last_index = None
  5.         for index, char in enumerate(str):
  6.             if char == "X":
  7.                 if is_X is None:
  8.                     is_X = True
  9.                     last_index = index. From 1point 3acres bbs
  10.                 # if last seen valid character is Y
  11.                 if is_X = False:
  12.                     dist = index - last_index
  13.                     min_dist = min(min_dist, dist). 1point3acres.com
  14.                     is_X = True
  15.                     last_index = index
  16.                 # if last seen valid cahracter is X
  17.                 if is_X = True:
  18.                     last_index = index
  19.             if char == "Y":
  20.                 if is_X is None: ..
  21.                     is_X = False. 1point3acres
  22.                     last_index = index
  23.                 # if last seen valid character is X
  24.                 if is_X = True: ..
  25.                     dist = index - last_index
  26.                     min_dist = min(min_dist, dist)
  27.                     is_X = False
  28.                     last_index = index. check 1point3acres for more.
  29.                # if last seen valid cahracter is Y
  30.                 if is_X = False:
  31.                     last_index = index
  32.         return min_dist
复制代码


.1point3acres
Problem 2: get min distance between X Y 2D version
. Waral dи,
description:

2d array with 3 types of characters: X Y and O, get the shortest distance between any pair of X and Y
OOOOXX
XOOOOO
OOYYOO

Output = 3

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


求大米!十分感謝!
八月要去onsite
                           
                  
                  
                  

. 1point3acres
. 1point 3acres
. 1point 3acres

评分

参与人数 1大米 +1 收起 理由
lastmayday + 1 很有用的信息!

查看全部评分


上一篇:请问布伦伯格何时做budget plan?(HC高峰)
下一篇:【19fall萌新求助】如何早早经营起LinkedIn账号

本帖被以下淘专辑推荐:

🔗
qazws 2019-7-13 03:28:53 | 只看该作者
全局:
Problem 2 的一个O(m*n)的思路,用BFS:
先取得所有X,Y坐标
对存储的X做BFS,检查相邻的格子,如果有Y就返回当前步数,如果有O就标记为X并加入下一次BFS的列表
对Y重复上一个步骤
这样每个格子都最多走过一次,得到O(m*n)
在XY数量都很多的时候(lz解法的worst case)效率高

评分

参与人数 1大米 +1 收起 理由
katyprogrammer + 1 很有用的信息!

查看全部评分

回复

使用道具 举报

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

本版积分规则

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