谷歌onsite 5轮
1: 一个maze 你有一个出发点和一个终点 问怎么样最快走道终点
具体题目是什么样子 google 一下maze 就知道了
要点是怎么表达这个图
有两种方式 一种是
class Position(object):
def __init__(self):
upWall = False
downWall = False
怎么distribute work- # Given a dictionary of a directed graph, representing nested groups and their members, flatten the structure and return all the groups a user belongs to directly and indirectly.
- # Group0 ------+--+--> Group3 ---> Group4
- # / /
- # Group1 ----+ /
- # /
- # Group2 ----+
- # \
- # +-------------> Group5
- # users_by_groups
- # Group -> [user1, user2, ..., usern]
- # Example input
- MEMBERS_BY_GROUPS = {
- 'Group0': {
- 'NestedGroups': ['Group3'],
- 'Members': ['User0', 'User1']
- },
- 'Group1': {
- 'NestedGroups': ['Group3'],
- 'Members': ['User2', 'User3', 'User4']
- },
- 'Group2': {
- 'NestedGroups': ['Group3', 'Group5'],
- 'Members': ['User4', 'User5']
- },
- 'Group3': {
- 'NestedGroups': ['Group4'],
- 'Members': ['User6', 'User7']
- },
- 'Group4': {
- 'NestedGroups': [],
- 'Members': ['User8', 'User9']
- },
- 'Group5': {
- 'NestedGroups': [],
- 'Members': ['User10', 'User11']
- }
- }
- # Example output:
- GROUPS_BY_USERS = {'User6': ['Group1', 'Group0', 'Group3', 'Group2'],
- 'User7': ['Group1', 'Group0', 'Group3', 'Group2'],
- 'User4': ['Group1', 'Group2'],
- 'User5': ['Group2'],
- 'User2': ['Group1'],
- 'User3': ['Group1'],
- 'User0': ['Group0'],
- 'User1': ['Group0'],
- 'User8': ['Group4', 'Group1', 'Group0', 'Group3', 'Group2'],
- 'User9': ['Group4', 'Group1', 'Group0', 'Group3', 'Group2'],
- 'User10': ['Group5', 'Group2'],
- 'User11': ['Group5', 'Group2']
- }
- def getGroup(data):
- res = {}
- for elem in data:
- for member in data[elem]['Members']:
- if member not in res:
- res[member] = []
- stack = [elem]
- while stack:
- top = stack.pop()
- res[member].append(top)
- for subelem in data:
- if top in data[subelem]['NestedGroups']:
- stack.append(subelem)
- for a in res:
- print a, res[a]
- #return res
-
- getGroup(MEMBERS_BY_GROUPS)
复制代码 bb 店面小哥问了 那题股票。。。 然后treenode next 那道。。后面那题装一下不懂 用了两种方法。。
不知道为什么还没给我onsite.. 所以发一下赞人品。。
附录一个自己整理的bb面经 记得用文本打开 我只是把他后缀变成pdf而已
补充内容 (2016-4-17 17:29):
下载完记得 mv bb.pdf bb.txt |