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

G家实习电面挂经

🔗
keke_shu 2016-11-27 12:42:19 | 只看该作者
全局:
wey066 发表于 2016-11-27 11:56
楼主你好!

我跟你同一天实习面试,至今没有hr回复,请问你有后续了吗?

那都已经两个多星期了啊,我前两天面的,听内推的学姐说过节这段时间可能会慢一些
回复

使用道具 举报

🔗
 楼主| wnbaicai 2016-11-27 12:43:20 | 只看该作者
全局:
夜皇雪 发表于 2016-11-27 03:36
问一下楼主,第一面第二题,你说给一个list,是指int nums[]这种还是List list 这种啊

没有说明,但是说了这些类似的条件都可以自己假定
回复

使用道具 举报

🔗
 楼主| wnbaicai 2016-11-27 12:45:04 | 只看该作者
全局:
wey066 发表于 2016-11-27 11:56
楼主你好!

我跟你同一天实习面试,至今没有hr回复,请问你有后续了吗?

17号已经通知挂了,你这应该是因为感恩节耽搁了,不过没有通知挂的话希望蛮大的
回复

使用道具 举报

🔗
夜皇雪 2016-11-27 12:55:56 | 只看该作者
全局:
google家电面都是不需要准确跑的吗??就是在google doc上写然后就是嘴跑大致思路啥没问题就行吗
回复

使用道具 举报

🔗
 楼主| wnbaicai 2016-11-28 01:30:56 | 只看该作者
全局:
夜皇雪 发表于 2016-11-27 12:55
google家电面都是不需要准确跑的吗??就是在google doc上写然后就是嘴跑大致思路啥没问题就行吗

不是,第一面开始code前明确说了要make sure don't crash,第二面写出来的码可以看到小哥全选了,应该是复制粘贴拿去跑了
回复

使用道具 举报

全局:
第一题用linkedlist就只能能找到吧
回复

使用道具 举报

🔗
衫衫水水 2016-11-28 09:12:59 | 只看该作者
全局:
zzgzzm 发表于 2016-11-9 12:00
第二面:这个题等价于求string s中的最长subsequence found in dictionary(注意是subsequence,不是substr ...

你确定你对题目的理解是对的?
回复

使用道具 举报

🔗
zzgzzm 2016-11-28 10:08:08 | 只看该作者
全局:
衫衫水水 发表于 2016-11-28 09:12
你确定你对题目的理解是对的?

你是指将题目转化为找最长的s的subsequence in dictionary?因为将s任意删去一些字母的操作和指定s的一个subsequence 是一一对应的(我包括了s本身也为其subsequence 的情况)。这样的等价转化不对吗?请指正。
回复

使用道具 举报

🔗
jacky841102 2016-11-29 17:27:16 | 只看该作者
全局:
用了trie合并字典中的prefix
预处理S,把a~z在S中的index按照先后次序存进charList中
idxs表示目前各个char的index
每选一个char需要把其他所有char的index增加使得其他的char index都比所选char index的还大

另外写了brute force的方法,和test的method
跑出来brute force的比较快啊。。。
10 个 case 的数据
trie time: 5.45
brute time: 0.08
trie time: 3.86
brute time: 0.05
trie time: 3.96
brute time: 0.05
trie time: 5.05
brute time: 0.07
trie time: 3.90
brute time: 0.05
trie time: 4.13
brute time: 0.05
trie time: 3.64
brute time: 0.05
trie time: 5.44
brute time: 0.07
trie time: 3.43
brute time: 0.04
trie time: 4.07
brute time: 0.05
单位是秒

  1. from random import choice, randint
  2. import string
  3. from time import time

  4. def dictSearch(S, words):
  5.     global ans
  6.     trie = Trie()

  7.     for word in words:
  8.         trie.insert(word)

  9.     charList = [list() for _ in range(26)]
  10.     for i, c in enumerate(S):
  11.         charList[ord(c) - ord('a')].append(i)

  12.     idxs = [0] * 26
  13.     ans = ""

  14.     def dfs(node, cur_idxs):
  15.         global ans
  16.         if node is None:
  17.             return
  18.         if node.isword and len(node.word) > len(ans):
  19.             ans = node.word
  20.         for i, child in enumerate(node.childs):
  21.             if child and cur_idxs[i] < len(charList[i]):
  22.                 idxs = list(cur_idxs)
  23.                 for j in range(26):
  24.                     while idxs[j] < len(charList[j]) and charList[j][idxs[j]] < charList[i][idxs[i]]:
  25.                         idxs[j] += 1
  26.                 dfs(child, idxs)
  27.         return

  28.     dfs(trie.root, idxs)
  29.     return ans

  30. class Trie:
  31.     def __init__(self):
  32.         self.root = TrieNode()

  33.     def insert(self, word):
  34.         i = self.root
  35.         for c in word:
  36.             t = ord(c) - ord('a')
  37.             if i.childs[t] == None:
  38.                 i.childs[t] = TrieNode()
  39.             i = i.childs[t]
  40.         i.isword = True
  41.         i.word = word

  42. class TrieNode:
  43.     def __init__(self):
  44.         self.isword = False
  45.         self.childs = [None] * 26
  46.         self.word = None


  47. def brute(S, words):
  48.     ans = ''
  49.     for word in words:
  50.         next = 0
  51.         for c in word:
  52.             next = S.find(c, next)
  53.             if next == -1:
  54.                 break
  55.         else:
  56.             if len(word) > len(ans):
  57.                 ans = word
  58.     return ans

  59. def test():
  60.     for i in range(10):
  61.         S = ''.join(choice(string.ascii_lowercase) for _ in range(randint(500,1000)))
  62.         words = [''.join(choice(string.ascii_lowercase) for _ in range(randint(10,20))) for _ in range(randint(10000, 20000))]
  63.         words.sort()

  64.         now = time()

  65.         trie_result = dictSearch(S, words)
  66.         print('trie time: %.2f' % (time() - now))

  67.         now = time()
  68.         brute_result = brute(S, words)
  69.         print('brute time: %.2f' % (time() - now))

  70.         assert(trie_result == brute_result)
复制代码
回复

使用道具 举报

🔗
blactangeri 2016-11-30 11:40:11 | 只看该作者
全局:
zzgzzm 发表于 2016-11-10 03:41
即使用O(|s|)时间判断字典中每个单词w是否是s的sunsequence,那么总时间O(|s|*|D|)也会有很多浪费的地方 ...

你好 如果是求longest substring应该怎么做

评分

参与人数 1大米 +3 收起 理由
zsmj001 + 3 欢迎来一亩三分地论坛!

查看全部评分

回复

使用道具 举报

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

本版积分规则

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