📣 黑五价提前开抢|VIP一年通行证5折,蓝莓、Offer多多同步特惠
楼主: cynthiazhxu
跳转到指定楼层
上一主题 下一主题
收起左侧

Google刚面完新鲜出炉Onsite3.9

🔗
dddxhh 2015-3-17 22:57:09 | 只看该作者
全局:
surpass count除了mergesort和用BST之外,还有一个做法。

逆序数就是求 在原数组里 后面有几个数比当前的数字大。

将每个元素的下标记下来,然后按照元素大小排序。 排好序之后从大到小往一个空的数组里插入(插入位置是它在原数组的位置)。 每个元素的逆序数 就是 它插入的时候 这个空数组的 suffix sum,这玩意直接用树状数组 logn算出来。
回复

使用道具 举报

🔗
charles901030 2015-3-18 04:04:10 | 只看该作者
全局:
同是3.9onsite, 楼主加油
回复

使用道具 举报

全局:
我23号面的 前两天通知已跪。。。祝好运
回复

使用道具 举报

🔗
bobingmm 2015-3-23 08:31:56 | 只看该作者
全局:
祝楼主拿到offer!
回复

使用道具 举报

🔗
shinichish 2015-3-25 12:54:00 | 只看该作者
全局:
averillzheng 发表于 2015-3-12 09:41
surpass的code。 求大牛点拨

大神,你能讲讲你的思路吗?code不太看得懂
回复

使用道具 举报

🔗
shinichish 2015-3-26 01:28:45 | 只看该作者
全局:
卧槽,第一题就是cc上面的一道题啊!真考了啊
回复

使用道具 举报

🔗
池大侠 2015-3-26 02:44:29 | 只看该作者
全局:
shinichish 发表于 2015-3-25 16:28
卧槽,第一题就是cc上面的一道题啊!真考了啊

which chapter?? I didnot see it...
回复

使用道具 举报

🔗
池大侠 2015-3-26 02:59:10 | 只看该作者
全局:
second one ... is it O(n^2)? cause we need to go through all the cases....
  1. def getfrac(k):
  2.         res = []
  3.         table = {}
  4.         for nomin in range(k):
  5.                 for denorm in range(1,k):
  6.                         val = 1.0 * nomin / denorm
  7.                         if val not  in table:
  8.                                 table[val] = [str(nomin) + '/' + str(denorm)]
  9.                         #else:
  10.                         #        table[val].append(str(nomin) + '/' + str(denorm))
  11.         print table
复制代码
回复

使用道具 举报

🔗
池大侠 2015-3-26 06:12:55 | 只看该作者
全局:
just did the surpass problem... with python...
  1. def mergersort(num, table):
  2.         if len(num) == 1:
  3.                 return num
  4.         def merge(left, right, table):
  5.                 left = list(left)
  6.                 right = list(right)
  7.                 merged = []
  8.                 midlen = len(left)
  9.                 while left and right:
  10.                         if left[0]<=right[0]:
  11.                                 merged.append(left.pop(0))
  12.                         else:
  13.                             merged.append(right.pop(0))
  14.                             table[left[0]] += 1
  15.                 while left:
  16.                         merged.append(left.pop(0))
  17.                 #right = list(right)
  18.                 while right:
  19.                         merged.append(right.pop(0))
  20.                 return merged
  21.         mid = len(num)/2
  22.         left = mergersort(num[:mid], table)
  23.         right = mergersort(num[mid:], table)
  24.         return merge(left, right, table)


  25. num = [7,1,9,2,0,4,5]

  26. table = {}
  27. for elem in num:
  28.         if elem not in table:
  29.                 table[elem] = 0

  30. mergersort(num,table)
  31. print table
复制代码
回复

使用道具 举报

🔗
shinichish 2015-3-26 10:13:46 | 只看该作者
全局:
池大侠 发表于 2015-3-25 10:44
which chapter?? I didnot see it...

Hard那一章
回复

使用道具 举报

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

本版积分规则

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