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

Twitter Intern OA 2題

全局:

2017(4-6月) 码农类General 硕士 实习@twitter - 网上海投 - 在线笔试  | | Other | 其他

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
今天打開來發現只有兩題
第一題是Genetic Mutation 這題和LC433 Minimum Genetic Mutation 一樣
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
etica Neue, Helvetica, Arial, sans-serif">請原諒我沒有權限po截圖

评分

参与人数 3大米 +63 收起 理由
阿童木 + 50
jigsaw_Becky + 10 感谢分享!
hkzy2001 + 3 感谢分享!

查看全部评分


上一篇:Linkedin 全套
下一篇:Coursera 2016年10月 OA题目
🔗
 楼主| rasca0027 2016-11-3 14:53:10 | 只看该作者
全局:
Genetic Mutation Python Code:


  1. def findMutationDistance(start, end, bank):
  2.     nu_start = toNumber(start)
  3.     nu_end = toNumber(end)
  4.     nu_bank = set(map(toNumber, bank))
  5.     explored = set()
  6.     if nu_end not in nu_bank:
  7.         return -1
  8.     if nu_start == nu_end:
  9.         return 0
  10.     fringe = [(nu_start, 0)]
  11.     while fringe != []:
  12.         node = fringe.pop(0)
  13.         now = node[0]
  14.         depth = node[1]
  15.         
  16.         if now == nu_end:
  17.             return depth
  18.         for x in range(8):
  19.             for y in range(4):
  20.                 successor = now ^ (y << (x * 2))
  21.                 if successor in nu_bank and successor not in explored:
  22.                     explored.add(successor)
  23.                     fringe.append((successor, depth + 1))
  24.     return -1


  25. def toNumber(s):
  26.     # s to bi
  27.     table = {'A':0, 'C':1, 'G':2, 'T':3}
  28.     val = 0
  29.     for i in s:
  30.         val = table[i] + (val << 2)
  31.     return val
复制代码
回复

使用道具 举报

🔗
 楼主| rasca0027 2016-11-3 14:55:08 | 只看该作者
全局:
我過了 已補上代碼在一樓
回复

使用道具 举报

🔗
奇奇蒂蒂 2016-11-5 05:02:52 | 只看该作者
全局:
rasca0027 发表于 2016-11-3 14:55
我過了 已補上代碼在一樓

楼主 求第二题的代码!
回复

使用道具 举报

🔗
 楼主| rasca0027 2016-11-5 05:22:21 | 只看该作者
全局:
  1. interval = raw_input()
  2. start = interval.split(', ')[0]
  3. end = interval.split(', ')[1]

  4. empty = raw_input()
  5. aggregation = {}

  6. year = start[:4]
  7. month = start[5:7]
  8. while True:
  9.     s = year + '-' + month
  10.     if s == end:
  11.         break
  12.     aggregation[s] = {}
  13.     month = int(month) + 1
  14.     if month < 10:
  15.         month = '0' + str(month)
  16.     elif month > 12:
  17.         month = '01'
  18.         year = str(int(year) + 1)
  19.     else:
  20.         month = str(month)
  21. while True:
  22.     data = raw_input()
  23.     if data == '':
  24.         break
  25.     entry = data.split(', ')
  26.     month = entry[0][:-3]
  27.     action = entry[1]
  28.     count = int(entry[2])
  29.     if month in aggregation:
  30.         if action in aggregation[month]:
  31.             aggregation[month][action] += count
  32.         else:
  33.             aggregation[month][action] = count

  34. for item in sorted(aggregation, reverse=True):
  35.     if aggregation[item] != {}:
  36.         print item + ', ' + ', '.join(k+', '+ str(aggregation[item][k]) for k in sorted(aggregation[item]))
复制代码
回复

使用道具 举报

🔗
SilentShawn 2016-11-6 01:24:59 | 只看该作者
本楼:
全局:
楼主好人!!
回复

使用道具 举报

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

本版积分规则

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