楼主: jerrydream
跳转到指定楼层
上一主题 下一主题
收起左侧

亚麻3月 北美面经

🔗
 楼主| jerrydream 2020-4-6 21:49:58 | 只看该作者
全局:
huang_anthea 发表于 2020-4-6 12:26
我突然想到,dfs是这样的吗?

输入如果是 -》 [a,b],,[e,f],[l,o]...
  1. from collections import Counter
  2. from collections import namedtuple

  3. # return True if word can be formed
  4. # false otherwise
  5. def dfs(tuples, d):                # both are
  6.         if len(d) == 0:                # all letters found match
  7.                 return True


  8.         if len(tuples) == 0:        # no more avaliable tuples to choose
  9.                 return False


  10.         for char, count in d.items():
  11.                 candidate_tuples = [t for t in tuples if char in t]                # all the tuples contain this
  12.                 for t in candidate_tuples:
  13.                         d[char] -= 1
  14.                         if d[char] == 0:
  15.                                 del d[char]

  16.                         tuples[t] -= 1
  17.                         if tuples[t] == 0:
  18.                                 del tuples[t]

  19.                         if dfs(tuples, d):
  20.                                 return True

  21.                         # backtracking
  22.                         d[char] = d.get(char, 0) + 1
  23.                         tuples[t] = tuples.get(t, 0) + 1

  24.         return False


  25. def main(lst_of_tupules, target):
  26.         # first, change the tuples into a dictionary, since only the count of each letter matters
  27.         d = Counter(target)                        # "hello" => {"h": 1, "e": 1, "l": 2, "o":1}
  28.         tuples = Counter(lst_of_tupules)                # [("a", "b"), ("c", "d"), ("c", "d")]                =>  {("a", "b"): 1, ("c", "d"): 2}
  29.         return dfs(tuples, d)


  30. """Let the size of tuples be n, let the lenght of target word be n,
  31. Time: O(m ** n), Exponential
  32. Space: O(m + n), since we create two additional dictionary
  33. """


  34. if __name__ == '__main__':
  35.         Test = namedtuple('Test', ['tuples_lst', 'target_word'])
  36.         test1 = Test(tuples_lst = [("a", "b"), ("c", "d"), ("h", "e")], target_word="ade")
  37.         assert(main(test1.tuples_lst, test1.target_word) == True)

  38.         test2 = Test(tuples_lst = [("a", "b"), ("c", "d"), ("h", "e")], target_word="hello")
  39.         assert(main(test2.tuples_lst, test2.target_word) == False)

  40.         test3 = Test(tuples_lst = [("h", "e"), ("f", "e"), ("l", "e"), ("l", "e"), ("m", "n"), ("o", "h")], target_word="hello")
  41.         assert(main(test3.tuples_lst, test3.target_word) == True)

  42.         test4 = Test(tuples_lst = [("h", "e"), ("f", "e"), ("l", "e"), ("l", "e"), ("m", "n")], target_word="hello")
  43.         assert(main(test4.tuples_lst, test4.target_word) == False)

  44.         test5 = Test(tuples_lst = [("t", "e"), ("p", "u"), ("a", "b"), ("c", "d"), ("m", "n")], target_word="tupac")
  45.         assert(main(test5.tuples_lst, test5.target_word) == False)

  46.         test6 = Test(tuples_lst = [("t", "e"), ("p", "u"), ("a", "b"), ("c", "d"), ("u", "p")], target_word="tupac")
  47.         assert(main(test6.tuples_lst, test6.target_word) == True)

  48.         test7 = Test(tuples_lst = [("t", "e"), ("p", "u"), ("a", "b"), ("c", "d"), ("p", "u")], target_word="tupac")
  49.         assert(main(test7.tuples_lst, test7.target_word) == True)


复制代码

评分

参与人数 1大米 +2 收起 理由
huang_anthea + 2 给你点个赞!

查看全部评分

回复

使用道具 举报

🔗
 楼主| jerrydream 2020-4-6 21:55:51 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
回复

使用道具 举报

🔗
 楼主| jerrydream 2020-4-6 21:59:42 | 只看该作者
全局:
Hhh123 发表于 2020-4-6 14:10
楼主是new grad吗 怎么面的这么难

研究生刚毕业, 不过走的是社招。 难不难看主观吧, recuriter 确实说过机器人组bar 高一些。 不过被拒还是只能怪自己水平不够,还得继续提高。

面试加油
回复

使用道具 举报

🔗
huang_anthea 2020-4-7 10:09:17 | 只看该作者
全局:
jerrydream 发表于 2020-4-6 21:55
刚刚的回复不懂为什么发不出来

我是从target word 开始search.  target word 里的每一个letter, 都从t ...

谢谢楼主啦
回复

使用道具 举报

🔗
 楼主| jerrydream 2020-4-7 10:25:07 | 只看该作者
全局:

客气 面试加油
回复

使用道具 举报

🔗
hdjsjyl 2020-4-8 17:17:37 | 只看该作者
全局:
请问dictionary里存的是什么, 比如key和value到底是什么可以产生memo的效果, 谢谢了
回复

使用道具 举报

全局:
请问第一轮是system design还是ood?online的话需要画图吗?感觉楼主很接近了,下一个面试肯定成功!
回复

使用道具 举报

🔗
Hhh123 2020-4-9 00:16:10 | 只看该作者
全局:
jerrydream 发表于 2020-4-6 21:59
研究生刚毕业, 不过走的是社招。 难不难看主观吧, recuriter 确实说过机器人组bar 高一些。 不过被拒还 ...

嗯嗯嗯 好 ,谢谢楼主
回复

使用道具 举报

🔗
 楼主| jerrydream 2020-4-9 09:56:21 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
回复

使用道具 举报

🔗
 楼主| jerrydream 2020-4-9 09:58:47 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
回复

使用道具 举报

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

本版积分规则

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