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

惨烈的google onsite (11.5)

🔗
Justin小白 2018-11-7 00:05:14 | 只看该作者
全局:
很详细。加油LZ!
回复

使用道具 举报

🔗
 楼主| martinchia 2018-11-7 00:17:16 | 只看该作者
全局:
nhqgoal 发表于 2018-11-6 11:41
请问猜字母到只剩一个下划线再开始猜词的策略是怎么得出的? 如果是aabbcc这种没有单独出现的字母呢?

那就不需要猜词了,因为在猜字母的阶段就猜出来了
回复

使用道具 举报

🔗
 楼主| martinchia 2018-11-7 00:19:24 | 只看该作者
全局:
nole 发表于 2018-11-6 23:36
请问最后一轮求汇率的题, 是哪到题?谢谢

不记得是哪道题了,大致的意思就是,比如给你A到B的汇率,B到C的汇率,C到D的汇率。有可能问你:
1. A到B的汇率
2. C到A的汇率
3. A到D的汇率
4. A到E的汇率(没有就返回0)
回复

使用道具 举报

🔗
 楼主| martinchia 2018-11-7 00:22:08 | 只看该作者
全局:
wtcupup 发表于 2018-11-6 11:34
请问LZ在Mountain View 面的还是Sunnyvale ?

mountain view
回复

使用道具 举报

🔗
wangyuc2 2018-11-7 00:30:26 | 只看该作者
全局:
martinchia 发表于 2018-11-7 00:19
不记得是哪道题了,大致的意思就是,比如给你A到B的汇率,B到C的汇率,C到D的汇率。有可能问你:
1. A到 ...

散酒酒吧应该是
回复

使用道具 举报

🔗
nole 2018-11-7 09:53:53 | 只看该作者
全局:
谢谢楼主。应该是散酒酒。
回复

使用道具 举报

🔗
nhqgoal 2018-11-7 09:56:47 | 只看该作者
全局:
楼主第一题如果你用两个bst存x 和 y的partition坐标, 那么怎么知道找到的坐标是第几个区间呢?
回复

使用道具 举报

🔗
kxace 2018-11-7 10:18:44 | 只看该作者
全局:
第一题感觉可以用两个BST with count of nodes of subtree做。
一个subtree代表横坐标切得刀未知,一个代表纵坐标切得位置
给定x,y 搜索时候分别找到X对应的column和Y对应row,最后的number = row * number of columns + columns就好
砍一刀的时候就是常规log n往下找 + update subtree sum
这个思路对嘛?
回复

使用道具 举报

🔗
happycsdogs 2018-11-7 13:36:52 | 只看该作者
全局:
请问第一题怎么做呢?binary tree 怎么构建啊
回复

使用道具 举报

🔗
 楼主| martinchia 2018-11-7 14:33:03 | 只看该作者
全局:
  1. class BinarySearchTree:
  2.     def __init__(self, val):
  3.         self.val = val
  4.         self.less_num = 0
  5.         self.greater_num = 0
  6.         self.left = None
  7.         self.right = None

  8. class Partitions:
  9.     def __init__(self):
  10.         self.xTree = None
  11.         self.yTree = None
  12.         self.max_x = 0
  13.         self.x_total = 1

  14.     def getPartition(self, x, y):
  15.         def getLess(tree, val):
  16.             cur = tree
  17.             total = 0
  18.             while cur:
  19.                 if val > cur.val:
  20.                     total += cur.less_num + 1
  21.                     cur = cur.right
  22.                 else:
  23.                     cur = cur.left
  24.             return total

  25.         if not self.xTree:
  26.             less_x = 0
  27.         else:
  28.             less_x = getLess(self.xTree, x)
  29.         if not self.yTree:
  30.             less_y = 0
  31.         else:
  32.             less_y = getLess(self.yTree, y)
  33.         if less_y == 0:
  34.             return less_x
  35.         else:
  36.             return less_y * self.x_total + less_x

  37.     def addVal2Tree(self, tree, val):
  38.         cur = tree
  39.         while cur:
  40.             if val > cur.val:
  41.                 cur.greater_num += 1
  42.                 if cur.right:
  43.                     cur = cur.right
  44.                 else:
  45.                     cur.right = BinarySearchTree(val)
  46.                     break
  47.             else:
  48.                 cur.less_num += 1
  49.                 if cur.left:
  50.                     cur = cur.left
  51.                 else:
  52.                     cur.left = BinarySearchTree(val)
  53.                     break

  54.     def addX(self, x):
  55.         if not self.xTree:
  56.             self.xTree = BinarySearchTree(x)
  57.             self.x_total = 2
  58.         else:
  59.             self.addVal2Tree(self.xTree, x)
  60.             self.x_total += 1

  61.     def addY(self, y):
  62.         if not self.yTree:
  63.             self.yTree = BinarySearchTree(y)
  64.         else:
  65.             self.addVal2Tree(self.yTree, y)

  66. if __name__ == "__main__":
  67.     p = Partitions()
  68.     p.addX(1)
  69.     print(p.getPartition(1, 2))
复制代码
回复

使用道具 举报

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

本版积分规则

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