注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
Google SG phone interview
date: 2019/June/11
. 1point3acres.com
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
X: 10.
Y: 12
→ Output = 12 - 10 = 2
interviewer agree with this solution
- def get_dist(str):
- min_dist = float('inf')
- is_X = None.
- last_index = None
- for index, char in enumerate(str):
- if char == "X":
- if is_X is None:
- is_X = True
- last_index = index
- # if last seen valid character is Y
- if is_X = False:
- dist = index - last_index
- min_dist = min(min_dist, dist)
- is_X = True
- last_index = index
- # if last seen valid cahracter is X
- if is_X = True:
- last_index = index
- if char == "Y":
- if is_X is None:
- is_X = False-baidu 1point3acres
- last_index = index
- # if last seen valid character is X
- if is_X = True:
- dist = index - last_index
- min_dist = min(min_dist, dist). .и
- is_X = False
- last_index = index
- # if last seen valid cahracter is Y
- if is_X = False:
- last_index = index
. From 1point 3acres bbs - return min_dist
复制代码
Problem 2: get min distance between X Y 2D version.
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
. 1point 3acres
Output = 3
求大米!十分感謝!
八月要去onsite
.--
. 1point 3 acres
. Waral dи,
|